UMLDiagrams
UMLDiagrams
State diagram - This diagram is used to describe the state of an object in a system.
Person
-String name
-String address
-String phone
-String email
+isStudent() : bool
+validate(Person) : bool
Attributes
Attributes are the properties of a class. An attribute is represented in the form of
[access modifier] [attribute name]: [attribute type]
The following are parts of an attribute:
Access modifier - Visibility of the attribute. It can be one of the following:
+ public
- private
# protected
~ package
Attribute name - Name of the attribute
Attribute type - Type of the attribute. It can be a primitive type or a class type.
Methods
Methods are the operations that can be performed on a class. A method is represented in
the form of
[access modifier] [method name]([parameter list]): [return type]
The following are parts of a method:
Access modifier - Visibility of the method. Same as the access modifier of an
attribute.
Method name - Name of the method
Parameter list - List of parameters that the method takes but instead of the
parameter name, the parameter type is used. The parameters are separated by
commas.
Return type - Type of the value returned by the method. It can be a primitive type or
a class type.
Static methods and attributes are underlined.
Interfaces and abstract classes
An interface is a contract that a class must implement. An interface is represented by a
rectangle with the name of the interface in the middle surrounded by an angled bracket.
The methods of the interface are presented in the rectangle.
«interface»
Walkable
+walk()
#int legs
+walk()
Relationships
There are 2 major types of relationships between classes:
Inheritance - A relationship between a superclass and a subclass. The subclass
inherits the attributes and methods of the superclass.
Association - A relationship between 2 classes. The classes are associated with
each other. The association can be one of the following:
Aggregation - A relationship between 2 classes where the lifetime of the child
class is dependent on the lifetime of the parent class. The child class can exist
without the parent class.
Composition - A relationship between 2 classes where the lifetime of the child
class is dependent on the lifetime of the parent class. The child class cannot exist
without the parent class.
Inheritance is represented by a line with an arrow pointing to the superclass. Sometimes
the arrow is replaced by a triangle.
Person
-String name
-String address
-String phone
-String email
+isStudent() : bool
+walk()
+validate(Person) : bool
«interface»
Walkable
+walk()
Aggregation is represented by a line with a diamond at the end of the line.
Student
-Person person
Person
-String name
-String address
-String phone
-String email
+isStudent() : bool
+validate(Person) : bool
Composition is represented by a line with a filled diamond at the end of the line.
Student
-Person person
Person
-String name
-String address
-String phone
-String email
+isStudent() : bool
+validate(Person) : bool
Cardinality
Cardinality is the maximum times an entity can relate to an instance with another
entity or entity set.
the number of interactions entities have with each other.
One to One (1:1)
A "one-to-one" relationship is seen when one instance of entity 1 is related to only
one instance of entity 2 and vice-versa
A student can only have one email address and one email address can be associated with
only one student.
Student
-String name
-String email
-String email
Student
-String name
-Batch batch
Batch
-String name
-Student[] students
An attribute shared by both entities can only be added to the entity which has multiple
instances i.e. the M side.
Many to Many (m:n)
When multiple instances of entity 1 are linked to multiple instances of entity 2, we
have a "many-to-many" relationship. Imagine a scenario where an employee is
assigned more than one project.
A student can attend multiple classes and a class can have multiple students.
Student
-String name
-Class[] classes
Class
-String name
-Student[] students