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
Extracting Type Hierarchies
- Examine interface and class declarations to identify type hierarchies
public ClassB extends ClassA implements InterfaceA, InterfaceB {
// ...
}
Note the closed arrowhead!
ClassB
ClassA
InterfaceA
InterfaceB
<<interface>>
<<interface>>
Extracting 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
Extracting 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
What does this class diagram communicate about relationships between objects of type ClassA, ClassB and ClassC?
ClassB
ClassA
ClassC
1
1
3
Aggregation
- 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 🏢
"...there is hardly a difference between aggregations and associations during implementation, and the diagram may skip aggregation relations altogether."
Lecture Ticket Review
Lecture Ticket Diagram
Lecture Lab
C4: Extracting UML Class Diagrams
The End - Thank You!
C4 Extracting UML Class Diagrams
By Steven Wolfman
C4 Extracting UML Class Diagrams
- 235