1. Class Notation
2. Generalization & Realization
public class A extends B { ... }
public class A implements B { ... }
3. Dependency & Association
3.0 Cardinality
In UML, cardinality is used to specify the number of instances of one class that can be associated with the instances of another class in an association.
Here are the different cardinality options and what they mean:
- 1: Indicates that there can be only one instance of the associated class.
- 0..1: Indicates that there can be zero or one instance of the associated class.
- 1..* or 1..n: Indicates that there can be one or more instances of the associated class.
- 0..* or * or n..*: Indicates that there can be zero or more instances of the associated class.
- m..n: Indicates that there can be a minimum of
m
instances and a maximum ofn
instances of the associated class. - 1..1: Indicates that there must be exactly one instance of the associated class. This is the same as cardinality of 1.
- 0..0: Indicates that there can be no instances of the associated class.
- n..n: Indicates that there must be exactly
n
instances of the associated class. This is the same as cardinality ofn
.
3.1 Dependency
Dependency in UML represents a relationship between two elements where one element, called the dependent element, relies on the other element, called the supplier element, in some way.
public class Car {
private Engine engine;
public Car() {
engine = new Engine();
}
public void start() {
engine.start();
}
}
public class Engine {
public void start() {
// start the engine
}
}
In this example, the Car
class depends on the Engine
class, since it needs an instance of Engine
to start.
3.2 Association
Association in UML represents a relationship between two elements where one element, called the source element, is related to the other element, called the target element, in some way.
3.2.1 Reflexive Association
public class Company {
private Set<Person> employees;
....
}
public class Person {
private Company company;
...
}
In this example, Company
has a set of Person
s, and Person
has a Company
.
3.2.2 Directed Association
public class Company {
private Set<Person> employees;
....
}
public class Person {
...
}
In this example, Company
has a set of Person
s, and Person
does not have a Company
.
4. Aggregation & Composition
I will update this part soon, please keep an eye on this note and check back for the latest version 👀