Professional Documents
Culture Documents
Structure
69
70 ________________________________________________________________ Structure
1
Customer
0..∗
0..∗
Appointment
1
1
1 1..∗
Employee Day Schedule
1
1..∗
Apprentice Assistant
Time Period
Figure 4.1: Class diagram for the Hair Salon System (Chapter 20)
tural relations between the classes and objects in our model. Figure 4.1
shows an example of a class diagram.
Even though we describe class and object structures together in the class
diagram, there is an important and decisive difference in their semantics.
Class structures express static, conceptual relations between classes. They
connect classes, and that relation does not change unless we change the de-
scription itself. The object structures, on the other hand, express dynamic,
concrete relations between objects. These relations can change dynamically
without any implied changes in the description.
We divide the structure activity into three subactivities, as Figure 4.3
shows. In the first subactivity, we combine our problem-domain knowledge
with the different structure types to produce candidates for structural rela-
tions among the selected classes and objects. In the second subactivity, we
explore the relevance of several general patterns to enhance our problem-
domain model. In the third subactivity, we evaluate and select the required
structural relations from our group of candidates.
72 ________________________________________________________________ Structure
Explore
patterns Evaluate
systematically
Class diagram
Generalization Structure
A generalization structure is a relation between two or more specialization
classes and a more general class:
Generalization: A general class (the super class) describes properties
common to a group of specialized classes (the subclasses).
Structures between Classes _______________________________________________ 73
For example, the classes “Taxi” and “Private Car” might be specializations
of the general class “Passenger Car,” as Figure 4.4 shows. Similarly, the
class “Vehicle” might be a further generalization of the classes “Passenger
Car” and “Truck.”
We call a specialized class a subclass and a generalized class a super
class. Linguistically, we express specialization with the formulation “is-a.”
You can use this to verify the correctness of a generalization candidate. We
must, for example, be able to say that “a taxi is a passenger car.” Figure 4.4
shows the graphical notation for a generalization structure. A generaliza-
tion structure is drawn as an arrow from the subclass to the super class. If
several arrows point to the same class, you can join the arrows as Figure
4.6 shows. The class diagram is easier to understand if all the arrows con-
sistently point upwards, implying that generalization classes are above
their specializations.
Passenger Car
The set of objects in each of the specialized classes is a subset of the set of
objects in the general class, and all subsets are mutually exclusive. This re-
lationship can be expressed in another way: Everything that holds true for
the general class also holds true for the specialized classes, whereas the
properties of a specialization class may only hold true for that particular
class.
The generalization structure expresses inheritance: Specialized classes
inherit the properties and behavioral pattern of the general class. Given
this, the general properties apply to all objects at the specialized level, in
addition to their own specialized properties. (We discuss problems that
arise with inherited behavioral patterns in Chapter 5.)
In some cases, we want to describe properties at an abstract level, even
if the problem domain contains no objects at that level. Figure 4.5 shows an
example in which the problem domain contains only employees and custom-
ers. Because the “Person” class contains no concrete objects, it is abstract,
but it is useful for describing properties that are common to and inherited
by both the employee and customer classes.
74 ________________________________________________________________ Structure
Person
Customer Employee
Account
Service Account
Cluster Structure
A cluster is a collection of classes that helps us achieve and provide a prob-
lem-domain overview:
Cluster: A collection of related classes.
A cluster conveys an overall understanding of a problem domain by divid-
ing it into smaller subdomains. The graphical notation is a file folder that
encloses the classes. Figure 4.7 shows an example of a model for an automo-
bile register. As the figure shows, a cluster is usually named after a central
Structures between Objects________________________________________________ 75
«cluster» «cluster»
Cars People
Car Owner
Cylinder Taxi
class: the “Cars” cluster consists of all classes pertaining to types of cars
and their components. Another cluster is composed of the classes describing
people associated with the cars. These two clusters summarize the model’s
basic structure.
Classes within a cluster are usually connected by either a generaliza-
tion structure or an aggregation structure. For example, this is the case
with the “Cars” cluster in Figure 4.7. Relations between classes from differ-
ent clusters are usually association structures. In Figure 4.7, “Owner” and
“Car” in two different clusters are related through an association structure.
Aggregation Structure
An aggregation structure is a relation between two or more objects. It ex-
presses that one object is a fundamental and defining part of the other:
76 ________________________________________________________________ Structure
Car
1 1 1
1 1 4..∗
1 1
1..∗ 2..∗
Association Structure
An association structure is also a relation between two or more objects, but
it differs from aggregation in that associated objects are not a defining
property of an object:
Find Candidates for Structure _____________________________________________ 77
0..∗
Car 1..∗
Person
Identify Generalizations
To generate candidates for generalization structures, we use approaches
similar to the ones we use for class selection.
In the first approach, we take every pair of selected classes and deter-
mine whether one of the two is a generalization of the other. If so, the gen-
eralization class events must be a subset of the specialization class events.
In the second approach, we determine if a relevant generalization class
exists for pairs of selected classes. For example, if our model contains cus-
tomers and suppliers, we might make a “business partner” generalization
class to contain common properties of the two original classes.
Our third approach is to take each of the selected classes and attempt
to define a relevant generalization or specialization. For example, if our
model contains employees, we can distinguish between different types of
employees according to the type of work they do. We express this by intro-
ducing several new classes that are specializations of the employee class.
Identify Aggregations
To find candidates for aggregation structures, we again systematically ex-
amine selected classes individually and in pairs.
In the first approach, we examine each pair of classes to see if the ob-
jects of one class might be a decomposition of the objects of the other class.
In the second approach, we determine if it is relevant to aggregate the
objects from each pair of classes into objects from a newly created whole-
class.
Our third approach is to determine if we can decompose each class into
a few relevant classes that do not yet exist in our model. Alternatively, we
consider aggregating the objects of a selected class into a new class.
You can use aggregation structures to describe a relatively broad spec-
trum of structural relations. For example, aggregation has a specific appli-
cation in block-structured programming languages, where a block aggre-
gates its constituent elements. In this case, the parts cannot exist without
the whole, since the block’s elements are typically created and destroyed at
the same time as the block itself. Such a “hard” definition of aggregation is
not particularly useful in object-oriented analysis. The parts in an aggrega-
tion structure will often live the first or last part of their lives independent
of the whole. Thus, we often have a defining relationship that conveys a
Find Candidates for Structure _____________________________________________ 79
Identify Associations
To generate candidates for association structures, we look at the remaining
class pairs to see if they can be meaningfully related. We should describe
associations whenever we must administrate, monitor, or control relations
between objects that are not otherwise related in the model.
Identify Clusters
To increase a class diagram’s clarity, we can explicitly group and name col-
lections of classes. This organizes conceptually related classes into clusters.
Figure 4.10 shows an example of a class diagram that gives a simple and
overall description of a problem domain.
«cluster»
Employees
«cluster» «cluster»
Customers Schedules
«cluster»
Appointment
Person Person
1 1
1..∗ 0..∗
Role Role
Person
1 1
1..∗ 1..∗
Employee Customer
Role Role
Another simplification of the role pattern is shown in Figure 4.5. This vari-
ant describes customers and employees as two specializations of a general
class. This variant provides a simple definition of the concepts, but it is dif-
ficult to use if some objects can be both customers and employees or if they
can switch dynamically between the two categories.
Person
1
0..∗
Party1
1
0..∗
Semester Leveln
1 1
0..∗ 0..∗
Class Leveln-1
1 1
0..∗ 0..∗
•••
Student
Level1
1
0..∗
Element
Book Descriptor
1 1
0..∗ 0..∗
Copy Item
4.7 Principles
The structure activity can be summarized in three fundamental principles
for the description of structure in our problem-domain model:
Study abstract, static relations between classes. We use generalization
and cluster structures to describe static, conceptual relations be-
tween classes. Generalization structures express different levels of
abstraction in our model, while we use clusters to achieve clarity.
Study concrete, dynamic relations between objects. We use aggregation
and association structures to describe dynamic, concrete relations
between objects. Aggregation structures describe superior objects as
consisting of or containing subobjects, while association structures
describe other meaningful relations between objects.
Model only the necessary structural relations. The model should describe
only the structural relations that are necessary to satisfy the system
definition. In general, the model should focus on the important as-
pects and contain a minimal number of structural relations.
Exercises ________________________________________________________________ 87
4.8 Exercises
Review Questions
1. What are the two different types of class structures?
2. What are the two different types of object structures?
3. Why is multiplicity only specified on object structures?
4. Why are abstract classes sometimes included in the model?
5. What is the meaning of inheritance? How is it described?
6. What is the meaning of multiple inheritance? Why is it a problem?
7. Why are clusters useful?
8. How do you choose between aggregation and association structures?
9. What is the basic technique for describing structures between classes
and objects?
10. What is the result of the structure activity?
Problems
11. Consider a situation with five cars and eight owners. Two cars have
one owner, the rest have two owners. Draw the objects and the owner-
ship relations. Create the corresponding class diagram.
12. Provide examples of the types of aggregation structures in Section 4.4.
13. Consider the role, relation, hierarchy, and item-descriptor patterns.
Identify examples of their use in the class diagrams in Chapters 19-21.
14. Review the class diagram in Chapter 20 using the criteria for system-
atic structure evaluation from this chapter. Are the structural rela-
tions appropriately described? Suggest possible alternatives.
15. Video rental store. Continue your considerations of the system for
managing customers and their rentals in a video rental store (see Ex-
ercise 3.13). Describe structural relations between classes and objects
in a class diagram.
16. Mobile phone. Continue your considerations of the system for a simple
mobile phone (see Exercise 3.14). Describe structural relations be-
tween classes and objects in a class diagram.
17. Teaching administration. Continue your considerations of the system
for monitoring student activities in a university department (see Exer-
cise 3.15). Describe structural relations between classes and objects in
a class diagram.
18. Elevator control. Continue your considerations of the system to control
elevator movement in a building (see Exercise 3.16). Describe struc-
tural relations between classes and objects in a class diagram.
88 ________________________________________________________________ Structure
4.9 Literature
All new object-oriented methods for analysis and design emphasize the de-
scription of structure. This is due to the central role that structure plays in
our understanding of the problem domain that we wish to model. While au-
thors agree on the importance of structure, they differ from each other both
with respect to the types of structures they describe, and the notation they
use. The methods that arise from traditions in object-oriented program-
ming have a very rich understanding of structure. For example, Booch
(1994) examines a broad spectrum of structures both between classes and
between objects. The examination is, however, somewhat technically ori-
ented; it is strongly characterized by facilities found in different object-ori-
ented programming languages. Booch’s rich structural understanding is
also seen in his examples illustrating how a specific type of structure can be
expressed in different programming languages. As a basis for the analysis,
he chooses to use facilities that can be realized technically.
Coad & Yourdon (1991a) represent an entirely different approach. They
use a general description of human knowledge as a starting point, and from
this substantiate the relevance of their structure types. Analysis is about
understanding something and expressing this understanding in a specific
language. Looking at human knowledge and using it as a basis for choosing
structure types is therefore more sensible than the technical approach,
which uses programming language facilities as a starting point. For this
reason, we place ourselves closer to the structure types found in Coad &
Yourdon (1991a).
A third direction comes from data modeling. An example of this ap-
proach is Shlaer & Mellor (1988). In data modeling, relations are the basic
building blocks. Some authors have combined relations with inheritance,
such that they operate only with generalizations and associations. Every
aggregation can naturally be described as an association; in this sense, the
two structure types are adequate. However, in our view, some object rela-
tions are of a fundamental and defining character, while others are more
fluid. We therefore maintain the distinction between aggregating and asso-
ciating.
UML, as described by Rumbaugh et al. (1999), has a huge variety of no-
tations for describing structure. That is because UML is a compromise, that
must be backwards compatible with earlier notations. In this chapter we
have selected a small and powerful subset of UML’s structural mechanisms
which will enable developers to model most problems. In Chapter 18 you
will find more UML structural notations.
Patterns are described by Coad (1995), Gamma et al. (1995), and Lar-
man (1998).