Java Reference
In-Depth Information
In OOD, each class can have one or more lower levels, called subclasses , or one or more higher
levels, called base classes or superclasses . For example, a class for Secretaries is a subclass of the
Employee class. Person is a base class or superclass of Employee. The relationship among the classes,
subclasses, and base classes is called the hierarchy . A high-level class diagram is a UML diagram used
to show the hierarchical relationships among classes (Figure A-18).
Manager
1
1.. *
indicates that each instance
must be associated with
one of the classes below it
indicates that each instance
must be associated with one
of the classes above it
Foreman
indicates that each Machine
must be assigned to at least
one Worker
1
1.. *
Assigned to
*
Worker
Machine
1
indicates that a Worker
can be associated with
more than one Machine
FIGURE A-18
Associations describe the manner in which instances of a class, or objects, are related. For exam-
ple, two instances of a Worker class can have the association of being coworkers. This type of associa-
tion is bidirectional , meaning each instance is associated with the other. Some associations are
unidirectional , which means that only one class is associated with the other. For example, a Worker
instance can be assigned to operate an injection molder machine, which is an instance of the class
Machines. The Worker is associated with the injection molder instance because a Worker must know
how to operate the injection molder, but the injection molder does not have any information about or
relationship to the Worker. In this way, the association between the Worker and Machine class is
unidirectional.
The high-level class diagram shown in Figure A-18 depicts a hierarchy in which an instance of the
Manager class can have several instances of the Foreman class associated with it; each instance of the
Foreman class can have several workers associated with it; and each instance of the Worker class can be
assigned to exactly one machine. Each class is represented by a box with the class name inside the box.
Relationships are designated by lines between the classes.
The 1 below the Manager class indicates that each Manager class must have at least one Foreman
class associated with it; the 1 below the Foreman class indicates that each Foreman class must have
at least one Worker class associated with it. The 1..* above the Foreman class indicates that each
Foreman class must be associated with at least one Manager class above it; the 1..* above the Worker
class indicates that each Worker class must be associated with at least one Foreman class above it. The
Assigned to label indicates that each Worker class is assigned to one Machine class. The 1 next to the
Machine class indicates that each Machine class must be assigned at least one Worker class. The * next
to the Worker class indicates that a worker can be associated with more than one Machine class.
Object-oriented programming (OOP) and OOD use many unique terms to describe program ele-
ments. In object-oriented terminology, the data stored about an object is called an attribute or prop-
erty. An attribute or property is an identifying characteristic of individual objects, such as a name,
 
Search WWH ::




Custom Search