Upload
garey-owens
View
217
Download
0
Embed Size (px)
Citation preview
UML Class Diagram
A class diagram shows
1. Classes
2. The relationships between them
Classes
Class name Class attributes (state) Class methods
(operations) Visibility
o + means publico # means protectedo − means privateo ~ means package
Course
name: Stringnumber: Integer
addStudent()
Class Details
Abstract class: name in italics Member properties:o statico abstracto CONSTANT
Specify type of attributes Specify signature and return value of
methods
addStudent( s : Student ) : void
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
Interfaces
«interface»Drawable
+draw(): void
Circle-radius: double+setRadius(r: double): void+getRadius(): double +draw(): void
implem
ent
Note dashed
line
Associations
When one class knows about another class and may call methods of that class’s objects General association Aggregation Composition dependency
Association
Specify that classes know each other Can be named (typically verbs)
CourseProfessorteaches
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
1 0..*teaches
Association
Classes can have role names (nouns) Typically represent attribute name in
other class
CourseProfessorteacher
Class Course { teacher: Professor; …}
Class Professor { myCourse: Course; …}
Association
Associations can be reflexive In this case role names are required
Professormentor
mentee
1
0..2
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 unspecifiedo To prohibit access use
TextBookCourse
Association Class
A class that represents the association
CourseStudent
0..* 0..*
Enrolment
grade: integer
Aggregation
One class contains an aggregate of objects from the other class
But aggregated objects are still independent
Implies container attribute
ProfessorDepartment
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
Aggregation Composition
Relationship has-a whole-parts
Container type references objects
Lifecycle elements are independent
elements are created with container and die with container
Elements can be in multiple aggregations
can be in only one composition
Dependency
One class uses anothero Local in methodo Argument to methodo 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»
Derived Attributes
An attribute whose value is derived from other attributes
Does not have a setter
Course
name: String/enrolment: Integer
addStudent()
Student
Constraints and Notes
Provide additional information
Course
capacity: integer/enrolment: integer
addStudent()
Student
{enrolment capacity}
Only nice ones
UML Class Diagrams
Object Diagrams
Similar to class diagrams Show object instances rather than
classes Reflect relationships at runtime No reflexive associationso ListNode class: next is reflexiveo ListNode object: next is reference to
another object