Post on 21-Dec-2021
UML
Structural Diagram
Class Diagram
Class Diagram
• To describe the types of objects in a system and their relationships.
• The classes in a class diagram represent both the main objects and or interactions in the application and the objects to be programmed.
• In the class diagram, classes are represented with boxes which contain three parts– The upper part holds the name of the class
– The middle part contains the attributes of the class, and
– The bottom part gives the methods or operations the class can take or undertake
Example of a Class
Figure 1: Class Customer
Figure 2: Class BankAccount
Relationships between Classes
• Used– during requirements analysis to model application domain
concepts
– during system design to model subsystems
– during object design to specify the detailed behavior and attributes of classes
• There are several relationships that might exist between classes. These includes:– Association
– Aggregation
– Generalization
Association
• The association relationship is the most common relationship in a class diagram. It shows the relationship between instances of classes.
• For example, the class Order is associated with the class Customer.
• The multiplicity of the association denotes the number of objects that can participate in the relationship. For example, an Order object can be associated to only one customer, but a customer can be associated to many orders.
Figure 3: Example of Association relationship
1-to-1 and 1-to-many Associations
Figure 5: 1-to-many association
Polygon
draw()
Point
x: Integer
y: Integer
*
Country
name:String
Capital
name:String
11
Figure 4: 1-to-1 association
Many-to-many Associations
StockExchange Company
tickerSymbolLists
**
• A stock exchange lists many companies.• Each company is identified by a ticker symbol
Figure 6: Many-to-many association
Aggregation
A variant of the "has a" or association relationship; aggregation is more specific than association. It is an association that represents a part-whole or part-of relationship
Graphically represented as a hollow diamond shape on the containing class
For example, we can think of Car as a whole entity and Car Wheel as part of the overall Car.
Figure 7: Example of Aggregation relationship
cont.. Aggregation
• A solid diamond denotes composition: A strong form of aggregation where the life time of the component instances is controlled by the aggregate. That is, the parts don’t exist on their won (“the whole controls/destroys the parts”)
TicketMachine
ZoneButton
3
Figure 8: Example of Composition relationship
Generalization
Figure 9:
Example of
Generalization
relationship
cont..Generalization
Generalization is another name for inheritance or an "is a" relationship.
It refers to a relationship between two classes where one class is a
specialized version of another.
To model generalization on a class diagram, a solid line is drawn from the
child class (the class inheriting the behavior) with a closed, unfilled
arrowhead (or triangle) pointing to the super class .
For example, Corporate Customer and Personal Customer are types of
Customer. So the classes Corporate Customer and Personal Customer
would have a generalization relationship with the class Customer.
The children classes inherit the attributes and operations of the parent
class.
Example of a Class Diagram
Figure 10: Example of a Class Diagram
Example of a Class Diagram in EA