CPSC 210

C4: Extracting UML Class Diagrams

Learning Goals

  • Extract a UML class design diagram from a given Java code base

UML Class Design Diagrams

  • A UML class design diagram is a model of the code
    • it does not include all the detail of the code
    • it facilitates communication about code design
    • it helps understanding the code
    • class diagram for existing codebase is useful if you
      • want to modify the functionality
      • want to extend the functionality

Type Hierarchies

  • Examine interface and class declarations to identify type hierarchies
public ClassB extends ClassA implements InterfaceA, InterfaceB {
  // ...
}

ClassB

ClassA

InterfaceA

InterfaceB

<<interface>>

<<interface>>

Arrowheads are "closed" for type hierarchies

Type Hierarchies

  • Examine interface and class declarations to identify type hierarchies
public ClassB extends ClassA implements InterfaceA, InterfaceB {
  // ...
}

ClassB

ClassA

InterfaceA

InterfaceB

<<interface>>

<<interface>>

Associations

  • Examine the fields of each class to identify associations
public ClassA {
  private List<ClassB> myListOfB;
  private ClassC myCObject;
}

public ClassC {
  private ClassA myAObject;
}

?

?

?

ClassB

ClassA

ClassC

Arrowheads are "open" for associations

Multiplicities

Identify the multiplicity of all associations:

  • for references to a single object: can that reference ever be null during the lifetime of the object to which it belongs?
  • for collections: how many items can be in the collection during the lifetime of the object to which that collection belongs?

Types vs Objects

Implements and extends relationships are relationships between types

Associations are relationships between objects

This class diagram reports on the relationships between objects of type ClassA, ClassB and ClassC

ClassB

ClassA

ClassC

1

1

3

Aggregation

"...there is hardly a difference between aggregations and associations during implementation, and the diagram may skip aggregation relations altogether."

  • We ask: "do associations have a whole/part relationship?"
    • ​In this case, a room makes no sense without a building!
  • ​However, there is a lot of room for interpretation!
    • ​You are your own designer - argue for your design!

Room 🚪

Building 🏢

Lecture Ticket Review

secret hint for Felix

Lecture Lab

C4: Extracting UML Class Diagrams

The End - Thank You!

CPSC210 - C4 Extracting UML Class Diagrams

By Felix Grund

CPSC210 - C4 Extracting UML Class Diagrams

  • 1,487