0% found this document useful (0 votes)
52 views12 pages

07 Class Relationship Diagram

The document discusses different types of relationships between classes in UML class diagrams including inheritance, association, aggregation, composition, dependency, and realization. Examples are provided for each relationship type to illustrate how they are depicted and their meaning relative to object-oriented programming concepts.

Uploaded by

summercuckoo1709
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views12 pages

07 Class Relationship Diagram

The document discusses different types of relationships between classes in UML class diagrams including inheritance, association, aggregation, composition, dependency, and realization. Examples are provided for each relationship type to illustrate how they are depicted and their meaning relative to object-oriented programming concepts.

Uploaded by

summercuckoo1709
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Class Relationship Diagram

FE Vol.2 Chapter 4 Development Technology: Additional notes

Reference: https://www.visual-paradigm.com/guide/uml-unified-modeling-language/uml-class-diagram-tutorial/
Relationships between classes
 UML is not just about pretty pictures.

 If used correctly, UML precisely conveys how code should be


implemented from diagrams.

 If precisely interpreted, the implemented code will correctly


reflect the intent of the designer.

 Can you describe what each of the relationships mean


relative to your target programming language shown in the
Figure below?

Chapter 4 Development Technology


Inheritance (or Generalization):
 A generalization is a taxonomic relationship between a more general classifier and a more specific classifier.

 Each instance of the specific classifier is also an indirect instance of the general classifier.

 Thus, the specific classifier inherits the features of the more general classifier.
 Represents an "is-a" relationship.
 An abstract class name is shown in italics.
 SubClass1 and SubClass2 are specializations of SuperClass.

The figure below shows an example of inheritance hierarchy.

 SubClass1 and SubClass2 are derived from SuperClass.

 The relationship is displayed as a solid line with a hollow arrowhead that points from the child element to
the parent element.

Chapter 4 Development Technology


Inheritance Example - Shapes
The figure below shows an inheritance example with two styles.

 Although the connectors are drawn differently, they are semantically equivalent.

Chapter 4 Development Technology


Association
 Associations are relationships between classes in a UML Class Diagram.

 They are represented by a solid line between classes.

 Associations are typically named using a verb or verb phrase which reflects the real world problem domain.

Simple Association
 A structural link between two peer classes.
 There is an association between Class1 and Class2

The figure below shows an example of simple association.

 There is an association that connects the <<control>> class Class1 and <<boundary>> class Class2.

 The relationship is displayed as a solid line connecting the two classes.

Chapter 4 Development Technology


Cardinality
Cardinality is expressed in terms of:

 one to one

 one to many

 many to many

Chapter 4 Development Technology


Aggregation
 A special type of association.
 It represents a "part of" relationship.
 Class2 is part of Class1.
 Many instances (denoted by the *) of Class2 can be associated with Class1.
 Objects of Class1 and Class2 have separate lifetimes.

The figure below shows an example of aggregation.

 The relationship is displayed as a solid line with a unfilled diamond at the association end, which is
connected to the class that represents the aggregate.

Chapter 4 Development Technology


Composition
 A special type of aggregation where parts are destroyed when the whole is destroyed.

 Objects of Class2 live and die with Class1.

 Class2 cannot stand by itself.

The figure below shows an example of composition.

 The relationship is displayed as a solid line with a filled diamond at the association end, which is connected
to the class that represents the whole or composite.

Chapter 4 Development Technology


Dependency
 An object of one class might use an object of another class in the code of a method.

 If the object is not stored in any field, then this is modeled as a dependency relationship.
 A special type of association.
 Exists between two classes if changes to the definition of one may cause changes to the other (but
not the other way around).
 Class1 depends on Class2 The figure below shows another example of
dependency. The Person class might have a hasRead
The figure below shows an example of dependency. method with a Book parameter that returns true if
• The relationship is displayed as a dashed line the person has read the book (perhaps by checking
with an open arrow. some database).

Chapter 4 Development Technology


Realization
 Realization is a relationship between the blueprint class and the object containing its respective
implementation level details.

 This object is said to realize the blueprint class.

 In other words, you can understand this as the relationship between the interface and the implementing
class.

 For example, the Owner interface might specify methods for acquiring
property and disposing of property. The Person and Corporation
classes need to implement these methods, possibly in very different
ways.

Chapter 4 Development Technology


Class Diagram Example: Order System

Chapter 4 Development Technology


Class Diagram Example: GUI

Chapter 4 Development Technology

You might also like