[2/24/2020] - I should update this page using examples from mexm-base, and rewrite the prose. A lot of this prose is taken from [1], but the examples aren't very clear. I should probably also implement this into python3 stub classes, so people who read this become familiar with it.
The declaration of classes is pretty simple
@startuml
class class_1
class class_2
@enduml
f two classes in a model need to communicate with each other, there must be a link between them, and that can be represented by an association (connector).
Association can be represented by a line between these classes with an arrow indicating the navigation direction. In case an arrow is on both sides, the association is known as a bidirectional association.
We can indicate the multiplicity of an association by adding multiplicity adornments to the line denoting the association. The example indicates that a Student has one or more Instructors:
@startuml
class Student
class Teacher
'a single student can associate with multiple teachers
Student "1..N" -- Teacher: learns from >
@enduml
This example indicates that every Instructor has one or more Students:
@startuml
class Student
class Teacher
'a teacher has multiple students
Student "1..N" -- Teacher: learns from <
@enduml
@startuml
' this example doesn't work, need to look how to do this
class Student
class Teacher
Student "1..N" -- "1..N" Teacher: teacher <
Student "1..N" -- "1..N" Teacher: learns from >
@enduml
We will go over the three types of association connectors: association, aggregation, and composition. These examples are taken from [1]
Aggregation and Composition are subsets of association meaning they are specific cases of association. In both aggregation and composition object of one class "owns" object of another class. But there is a subtle difference.:
[Figure 1] Composition of a Person class from three classes: Head, Hand and Leg
@startuml
class Person
class Head
class Hand
class Leg
Person *-- Head
Person *-- Hand
Person *-- Leg
@enduml
[Figure 2] Composition of a Person class from three classes: Head, Hand and Leg
@startuml
class EngineInspection
class Car
class Engine
class Wheel
Car o-- Engine
Car o-- Wheel
EngineInspection *-- Engine
@enduml
Generalization is the term that we use to denote abstraction of common properties into a base class in UML. The UML diagram's Generalization association is also known as Inheritance. When we implement Generalization in a programming language, it is often called Inheritance instead. Generalization and inheritance are the same. The terminology just differs depending on the context where it is being used.
We should be more specific and use the composition link in cases where in addition to the part-of relationship between Class A and Class B - there's a strong lifecycle dependency between the two, meaning that when Class A is deleted then Class B is also deleted as a result
[1] Visual Paradigm. "UML Association vs Aggregation vs Composition"