Java Reference
In-Depth Information
A unique object — a specific use of a class — is called an instance . Think of
an instance as a proper noun. For example, option buttons are used in a graphi-
cal user interface to allow users to choose one option from a list of options. All
option buttons belong to the class of option button objects that have the same
attributes and the same method of displaying as selected or not selected. The
label that accompanies a specific option button, however, has a unique value and
signifies a particular instance of an option button. For example, an option but-
ton to select a shipping method is a unique instance of the general class of
option button objects. Just as a proper noun represents a unique person or place,
each instance has a unique name, such as ShippingOptionButton.
VERBS An operation , or service, is an activity that reads or manipulates the
data of an object. You can think of an operation as an active verb. Examples of
operations include the standard mathematical, statistical, and logical operations,
as well as the input, output, and storage operations associated with computer
data. Object-oriented programmers use the term method to refer to code used to
perform the operation or service. The Shipment object, for example, performs
the operation of calculating shipping charges using the getShipping() method.
For an object to do something, it must receive a message. A message acti-
vates the code to perform one of the operations. Everything an object can do is
represented by the message. The message has two parts — the name of the
object to which the message is being sent, and the name of the operation that
will be performed. The impetus, or trigger , that causes the message to be sent
may come from another object or an external user. The entire process of a trig-
ger sending a message that causes an operation to occur is called an event . For
example, if you click the Calculate Shipping button to determine shipping
charges based on weight, clicking the button is the trigger that sends a message
to the Shipment object. The Shipment object then uses the getShipping()
method to calculate shipping costs, which is the operation. In this example,
clicking the Calculate Shipping button is the trigger and the calculation of ship-
ping costs is the operation; together, they make a Calculate Shipping event.
Programmers often draw an event diagram to show relationships among
events and operations visually and to help plan how they will program events.
Event diagrams display the trigger as a shadowed button. When you draw an
event diagram, you list the external trigger that causes this event to happen in
the shadowed rectangle at the upper-left corner of the diagram (Figure 1-20).
Then you begin the next part of the diagram on an independent line, to show
that the trigger is external.
On the independent line, you list the internal processing that describes the
event. Many students find it helpful to describe what the computer senses at this
point or imagine themselves thinking from the processor's point of view.
Operations are shown in rounded rectangles as results of the event. Opera-
tion rectangles should be used to describe any visual or procedural inputs and
outputs, such as the mouse pointer changing to an hourglass. Some operations
cause no other events to occur; other operations, such as the Print request being
sent to the printer driver, serve as triggers for other events and send additional
messages. When possible, event diagrams are drawn left to right to represent a
sequence of events over time.
Search WWH ::




Custom Search