5.2 Essentials of UML Class Diagrams The main symbols shown on class diagrams are: asses represent the types of data themselves · associations represent linkages between instances of classes Attributes are simple data found in classes and their instances perations represent the functions performed by the classes and their Instances · Generalizations group classes into inheritance hierarchies www.oseng.com O Lethbridge/Laganiere 2001 Chapter 5: Modelling with classes 6
© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes 6 5.2 Essentials of UML Class Diagrams The main symbols shown on class diagrams are: • Classes - represent the types of data themselves • Associations - represent linkages between instances of classes • Attributes - are simple data found in classes and their instances • Operations - represent the functions performed by the classes and their instances • Generalizations - group classes into inheritance hierarchies
Classes a class is simply represented as a box with the name of the class inside The diagram may also show the attributes and operations The complete signature of an operation is operationName( parameter Name: parameter Type.) return Type Rectangle Rectangle RectangleRectangle Rectangle getArea hei ght height height: int resize idth width width int getArea getArea(: int 柔e( int, int) www.oseng.com O Lethbridge/Laganiere 2001 Chapter 5: Modelling with classes
© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes 7 Classes A class is simply represented as a box with the name of the class inside • The diagram may also show the attributes and operations • The complete signature of an operation is: operationName(parameterName: parameterType …): returnType Rectangle height: int width: int getArea(): int resize(int,int) Rectangle height width getArea resize Rectangle height width Rectangle getArea resize Rectangle
5.3 Associations and Multiplicity An association is used to show how two classes are related to each other Symbols indicating multiplicity are shown at each end of the association Employee Company Secretary Manager Company BoardofDirectors Office 0.1 Employee Perso 0,3.8 BoardofDirectors www.oseng.com O Lethbridge/Laganiere 2001 Chapter 5: Modelling with classes 8
© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes 8 5.3 Associations and Multiplicity An association is used to show how two classes are related to each other • Symbols indicating multiplicity are shown at each end of the association 0,3..8 * Employee * * 1..** 0..1 * Secretary Office Person Company Employee Company Manager BoardOfDirectors BoardOfDirectors
Labelling associations Each association can be labelled to make explicit the nature of the association works For Employee Company Secretary Manager supervisor Company BoardofDirectors Office 0.1 allo catedTol Employee Person 0.3.8 BoardofDirectors bo ard Member wwseng. com O Lethbridge/Laganiere 2001 Chapter 5: Modelling with classes
© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes 9 Labelling associations • Each association can be labelled, to make explicit the nature of the association * supervisor 1..** * w orksFor 0..1 allocatedTo * boardMember 0,3..8 * Employee Secretary Office Person Company Employee Company Manager BoardOfDirectors BoardOfDirectors
Analyzing and validating associations One-to-one For each company there is exactly one board of directors a board is the board of only one company a company must always have a board a board must al ways be of some company Company BoardofDirectors www.oseng.com O Lethbridge/Laganiere 2001 Chapter 5: Modelling with classes
© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes 10 Analyzing and validating associations • One-to-one —For each company, there is exactly one board of directors —A board is the board of only one company —A company must always have a board —A board must always be of some company Company BoardOfDirectors