Objects
Individuals of a system:
Object Diagram
The objects of a system and their relationships, snapshot of objects at a specific moment in time:
Classes
A class is a construction plan for a set of similar object of a system.
Object are instances of classes.
- Attributes: structural characteristics of a class.
- Operations: behaviour of a class.
Attribute Syntax
Visibility
-
+
: public -> everybody. -
-
: private -> only the object itself. -
#
: protected -> class itself and subclasses. -
~
: package -> classes that are in the same package. -
/
: attribute is derived from other attributes, for example/age
as it is calculated from the date of birth.
Type
- User-defined classes.
- Data type:
- Primitive data type
- Pre-defined: Boolean, Integer, String.
- User-defined:
<<primitive>>
- Composite data type:
<<datatype>>
- Enumerations:
<<enumeration>>
- Primitive data type
Multiplicity
- Number of values an attribute may contain.
- Default value: 1
- Notation
[min..max]
- no upper limit:
[*]
or[0..*]
- no upper limit:
Properties
-
Pre-defined properties:
{readOnly}
: value cannot be changed.{unique}
: no duplicates permitted.{non-unique}
: duplicates permitted.{ordered}
: fixed order of the values.{unordered}
: no fixed order of the values.
-
Attribute specification:
- Set:
{unordered, unique}
- Multi-set:
{unordered, non-unique}
- Ordered set:
{ordered, unique}
- List:
{ordered, non-unique}
- Set:
Parameters
Similar to attributes.
- Direction of the parameter:
in
: input parameter.out
: output parameter.inout
: combined.
Class Variable and Class Operations
- Instance variable (instance attribute): attributes defined on instance level.
- Class variable (class attribute):
- Defined only per class, shared by all instances of the class.
- For example: counters for the number of instances of a class, constants, etc.
- Class operation:
- Can be used if no instance was created, for example: constructors, counting operations, math functions etc.
Specification of Classes: Different Levels of Detail
Association
Models possible relationships between instances of classes.
Binary Association
Connects two instances of two classes with one another.
Navigability
Object knows its partner objects and can therefore access their visible attributes and operations (open arrow head).
Non-Navigability
Indicated by a class, for example: A
can access attributes and operations of B
but B
cannot access any attributes and operations of A
.
Binary Association as Attribute
In Java:
class Professor()
class Student {
public Professor[] lecturer;
...
}
Multiplicity and role
Multiplicity: number of objects that may be associated with exactly one objet of the opposite side.
Role: the way in which an object is involved in an association relationship.
Xor Constraint
An object of class A
is to be associated with an object of class B
or an object of class C
but not with both.
Unary Association - Example
n-ary Association
More than two partner objects are involved in the relationship.
No navigation directions.
Association Class
Assign attributes to the relationship between classes rather than to a class itself.
Necessary when modelling n:m
Associations:
With 1:1
or 1:n
possible but not necessary:
Association Class vs Regular Class
Unique/Non-Unique
Aggregation
Special form of association used to express that a class is part of another class.
Properties of the aggregation association:
- Transitive: if
B
is part ofA
andC
is part ofB
,C
is also part ofA
. - Asymmetric: it is not possible for
A
to be part ofB
andB
to be part ofA
simultaneously.
Two types: shared aggregation and composition.
Shared Aggregation
- Expresses a weak belonging of the parts to a whole, meaning they also exist independently of the whole.
- Multiplicity at the aggregating end may be > 1, meaning one element can be part of multiple other elements simultaneously.
- Spans a directed acyclic graph.
- Syntax: hollow diamond at the aggregating end.
Example:
- Student is part of LabClass
- Course is part of StudyProgram
Composition
- Existence dependency between the composite object and its parts.
- Multiplicity at the aggregating end max of 1, the composite objects form a tree.
- If the composite object is deleted, its parts are also deleted.
- Syntax: solid diamond at the aggregating end.
Example:
- Beamer is part of LectureHall is part of Building.
Generalisation
- Characteristics (attributes and operations), associations, and aggregations that are specified for a general class (superclass) are passed on to its subclasses.
- Every instance of a subclass is simultaneously an indirect instance of the superclass.
- Subclass inherits all characteristics, associations, and aggregations of the superclass except private ones.
- Subclass may have further characteristics, associations, and aggregations.
- Generalisations are transitive.
Abstract Class
- Used to highlight common characteristics of their subclasses.
- Used to ensure that there are no direct instances of the superclass.
- Only its non-abstract subclasses can be instantiated.
- Useful in the context of generalisation relationships.
- Notation: keyword
{abstract}
or class name in italic font.
Multiple Inheritance
- UML allows multiple inheritance.
- A class may have multiple superclasses.
Example:
With vs Without Generalisation
Creating a Class Diagram
-
Not possible to completely extract classes, attributes and associations from a natural language text automatically.
-
Guidelines:
- Nouns often indicate classes.
- Adjectives indicate attribute values.
- Verbs indicate operations.
-
Example: The library management system stores users with their unique ID, name and address as well as books with their title, author and ISBN number.
Notation
Name | Notation | Description |
---|---|---|
Class | Description of the structure and behaviour of a set of objects. | |
Abstract Class | Class that cannot be instantiated. | |
Association | Relationship between classes where navigability is unspecified or bidirectional or one directional. | |
n-ary Association | Relationship between n (here 3) classes. | |
Association Class | More detailed description of an association. | |
xor Relationship | An object of C is in a relationship with A or with B but not both. | |
Shared aggregation | Parts-whole relationship (A is part of B ) | |
Strong aggregation (composition) | Existence-dependant parts-whole relationship (A is part of B ) | |
Generalisation | Inheritance relationship (A inherits from B ) | |
Object | Instance of class. | |
Link | Relationship between objects. |