📊

UML Class Diagrams Lecture

Jul 15, 2024

UML Class Diagrams Lecture

Introduction

  • Instructor: Bear
  • Topics Covered: Basic characteristics, relationships, examples

Basic Characteristics of Class Diagrams

  • Class Representation:

    • Classes represent objects or entities in the system.
    • Depicted by a rectangular shape divided into three sections.
  • Example: Zoo System

    • Class: Animal
      • Instance: Specific animal (e.g., Ruth)
      • Attributes: (middle section) – significant data for instances:
        • Name: name: String
        • ID: id: Integer
        • Age: age: Integer
      • Methods: (bottom section) – behavioral features of a class:
        • SetName: setName(name: String)
        • Eat: eat()

Visibility

  • Determines the accessibility of attributes and methods
    • Private (-): Not accessible by other classes
    • Public (+): Accessible by other classes
    • Protected (#): Accessible by the same class and its subclasses
    • Package (~): Accessible by any class in the same package (rarely used)

Example: Employee Class

  • Attributes:
    • Name name: String
    • Employee ID employeeID: Integer
    • Phone Number phoneNumber: Integer
    • Department department: String
  • Method:
    • Update Phone Number updatePhoneNumber(newNumber: Integer)

Relationships Between Classes

Inheritance

  • Concept: Subclasses inherit attributes and methods of a superclass.
  • Example:
    • Superclass: Animal
    • Subclasses: Tortoise, Otter, Slow Loris
    • Inheritance Relationship: Open arrow between child (subclass) and parent (superclass).
    • Animal Class: Abstract (use italics or special notation).

Association

  • Simple association relationship shown by a line.
  • Example: Otter eats Sea Urchin.

Aggregation

  • Whole-part relationship where parts can exist independently of the whole.
  • Example:
    • Class: Creep (Group of Tortoises)
    • Relationship: Open diamond with Tortoise class.

Composition

  • Strong whole-part relationship where parts cannot exist outside the whole.
  • Example:
    • Class: Visitor Center
    • Parts: Lobby, Bathroom
    • Relationship: Closed diamond.

Multiplicity

  • Numeric constraints on relationships.
    • One and only one: 1
    • One or many: 1..*
  • Examples:
    • Visitor Center has one lobby (1)
    • Visitor Center has one or many bathrooms (1..*)
    • Other notations: 0..1, N, 0..*, 1..*, specific ranges.

Practical Example

  • Scenario: Online Shopping Cart UML Diagram.
    • Class: User:
      • Attributes: userID, password, loginStatus, registerDate
      • Method: verifyLogin(): Boolean
    • Class Relationships:
      • Customer and Administrator inherit User.
      • Composition relationships: Customer and Shopping Cart, Orders, Shipping Info, Order Details.
    • Multiplicity:
      • Customer has zero or many orders (0..*).
      • Order belongs to one customer (1).
      • Order has one order detail (1).
      • Order Detail belongs to one order (1).*

Conclusion

  • Tool Used: Lucidchart
  • Further Learning: Visit training.lucid.co for more training on diagramming processes, systems, and organizations.