Relationships Describe how classes relate to one another Three basic types in UML Generalization Enables inheritance of attributes and operations Represents relationships that are ―a-kind-of‖ Aggregation Relates parts to wholes or assemblies Represents relationships that are ―a-part-of‖ or ―has-parts‖ Association Miscellaneous relationships between classes Usually a weaker form of aggregation
Generalization (
a-kind-of relationship) The generalization abstraction enables the analyst
to create classes that inherit attributes and operations of other classes. A
superclass contains basic attributes and operations that will be used in several
subclasses. –
The subclasses inherit the attributes and operations of their superclass and can also contain attributes and operations that are unique just to them. In this way, the analyst can reduce the redundancy in the class definitions
–
For example, a
customer class and an employee class can be generalized into a
person class by extracting the attributes and operations both have in common and placing them into the new superclass,
person. Thus
, an employee is
a-kind-of person.
Generalization (specialization & hierarchy) The analyst also can use the
opposite of generalization Specialization uncovers additional classes by allowing new subclasses to be created from an existing class. For example, an
employee class can be specialized into a
secretary class and an
engineer class. Furthermore, generalization relationships between classes can be combined
to form generalization hierarchies–
Based on the previous examples, a
secretary class and an
engineer class can be subclasses of an
employee class, which in
turn could be a subclass of a person class. This would be read as a secretary and an engineer are a-kind-of employee and a customer and an employee are a-kind-of person.
Generalization (
substitutability
) To ensure that the semantics of the subclasses are maintained, the analyst should apply the principle of
substitutability. •
By this we mean that the subclass should be capable of substituting for the superclass anywhere that uses the superclass (e.g., anywhere we use the employee superclass, we could also logically use its secretary subclass. By focusing on the a-kind-of interpretation of the
generalization relationship, the principle of substitutability is applied.
Aggregation (
a-part-of / has-parts
) Generally speaking, all aggregation relationships relate
Share with your friends: