1 / 20

UML Class Diagram

UML Class Diagram. A class diagram shows Classes The relationships between them. Classes. Class name Class attributes (state) Class methods (operations) Visibility + means public # means protected − means private ~ means package. Course. name: String number: Integer.

rolandm
Download Presentation

UML Class Diagram

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UML Class Diagram

  2. A class diagram shows • Classes • The relationships between them

  3. Classes • Class name • Class attributes (state) • Class methods (operations) • Visibility • + means public • # means protected • − means private • ~ means package Course name: String number: Integer addStudent()

  4. Class Details • Abstract class: name in italics • Member properties: • static • abstract • 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 Think “tree” not “arrow” Circle -radius: double override +setRadius(r: double): void +getRadius(): double +getArea(): double

  6. Interfaces «interface» Drawable +draw(): void Note dashed line Circle -radius: double implement +setRadius(r: double): void +getRadius(): double +draw(): void

  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) Professor Course 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 Professor Course teaches 1 0..*

  10. Association • Classes can have role names (nouns) • Typically represent attribute name in other class Professor Course teacher Class Professor { myCourse: Course; … } Class Course { teacher: Professor; … }

  11. Association • Associations can be reflexive • In this case role names are required Professor mentor 1 mentee 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 • To prohibit access use Course TextBook

  13. Association Class • A class that represents the association Student Course 0..* 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 Department Professor

  15. Composition • A stronger form of aggregation • One class contains objects from the other class • These objects have no existence without the containing object Program Course 1

  16. Dependency • One class uses another • Local in method • Argument to method • Creation of objects (e.g. factory) • But it is not an attribute (field) • Usually many; show only important ones B A C «creates» method(arg : B)

  17. Derived Attributes • An attribute whose value is derived from other attributes • Does not have a setter Course name: String /enrolment: Integer addStudent() Student

  18. Constraints and Notes • Provide additional information Course capacity: integer /enrolment: integer {enrolment  capacity} addStudent() Student Only nice ones

  19. Object Diagrams • Similar to class diagrams • Show object instances rather than classes • Reflect relationships at runtime • No reflexive associations • ListNode class: next is reflexive • ListNode object: next is reference to another object UML Class Diagrams

More Related