Download presentation
Presentation is loading. Please wait.
Published byGarey Owens Modified over 9 years ago
1
UML Class Diagram
2
A class diagram shows 1.Classes 2.The relationships between them
3
Classes Class name Class attributes (state) Class methods (operations) Visibility o + means public o # means protected o − means private o ~ means package Course name: String number: Integer addStudent()
4
Class Details Abstract class: name in italics Member properties: o static o abstract o CONSTANT Specify type of attributes Specify signature and return value of methods addStudent( s : Student ) : void
5
Inheritance Shape -color: Color +setColor(c: Color): void +getArea(): double Circle -radius: double +setRadius(r: double): void +getRadius(): double +getArea(): double Think “tree” not “arrow” override
6
Interfaces «interface» Drawable +draw(): void Circle -radius: double +setRadius(r: double): void +getRadius(): double +draw(): void implement Note dashed line
7
Associations When one class knows about another class and may call methods of that class’s objects General association Aggregation Composition dependency
8
Association Specify that classes know each other Can be named (typically verbs) CourseProfessor teaches
9
Multiplicity Specify the numerical relationship 1 – exactly one 0..1 – zero or one 0..* (or just *) – any number or none 1..* – one or more 3..8 – three to eight CourseProfessor 10..* teaches
10
Association Classes can have role names (nouns) Typically represent attribute name in other class CourseProfessor teacher Class Course { teacher: Professor; … } Class Professor { myCourse: Course; … }
11
Association Associations can be reflexive In this case role names are required Professor mentor mentee 1 0..2
12
Navigability The course knows the textbook(s) used The textbook does not know course(s) which use it Alternative interpretation: navigability from textbook to course is unspecified o To prohibit access use TextBookCourse
13
Association Class A class that represents the association CourseStudent 0..* Enrolment grade: integer
14
Aggregation One class contains an aggregate of objects from the other class But aggregated objects are still independent Implies container attribute ProfessorDepartment
15
Composition A stronger form of aggregation One class contains objects from the other class These objects have no existence without the containing object CourseProgram 1
16
AggregationComposition Relationshiphas-awhole-parts Container typereferencesobjects Lifecycleelements are independent elements are created with container and die with container Elementscan be in multiple aggregations can be in only one composition
17
Dependency One class uses another o Local in method o Argument to method o Creation of objects (e.g. factory) But it is not an attribute (field) Usually many; show only important ones CA method(arg : B) B «creates»
18
Derived Attributes An attribute whose value is derived from other attributes Does not have a setter Course name: String /enrolment: Integer addStudent() Student
19
Constraints and Notes Provide additional information Course capacity: integer /enrolment: integer addStudent() Student {enrolment capacity} Only nice ones
20
Object Diagrams Similar to class diagrams Show object instances rather than classes Reflect relationships at runtime No reflexive associations o ListNode class: next is reflexive o ListNode object: next is reference to another object UML Class Diagrams
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.