Objects

Individuals of a system:

Screenshot 2022-10-21 at 13.10.25

Object Diagram


The objects of a system and their relationships, snapshot of objects at a specific moment in time:

Screenshot 2022-10-21 at 13.11.07|500

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.

Screenshot 2022-10-21 at 13.12.30|200

Screenshot 2022-10-21 at 13.12.54|350

Attribute Syntax


Screenshot 2022-10-21 at 13.13.11

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>>

Multiplicity

  • Number of values an attribute may contain.
  • Default value: 1
  • Notation [min..max]
    • no upper limit: [*] or [0..*]

400

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}

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.

Screenshot 2022-10-21 at 13.27.01|600

Specification of Classes: Different Levels of Detail


Screenshot 2022-10-21 at 13.27.38|600

Association


Models possible relationships between instances of classes.

Screenshot 2022-10-21 at 13.28.01|500

Binary Association


Connects two instances of two classes with one another.

Screenshot 2022-10-21 at 13.28.30|560

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.

Screenshot 2022-10-21 at 13.30.17|200

Screenshot 2022-10-21 at 13.30.34|400

Binary Association as Attribute

Screenshot 2022-10-21 at 13.31.06|500

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.

Screenshot 2022-10-21 at 13.32.02|500

Role: the way in which an object is involved in an association relationship.

Screenshot 2022-10-21 at 13.32.24|400

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.

Screenshot 2022-10-21 at 13.33.17|400

Unary Association - Example


Screenshot 2022-10-21 at 13.33.44|600

n-ary Association


More than two partner objects are involved in the relationship.

No navigation directions.

Screenshot 2022-10-21 at 13.34.24|450

Screenshot 2022-10-21 at 13.34.43|500

Association Class


Assign attributes to the relationship between classes rather than to a class itself.

Screenshot 2022-10-21 at 13.36.08|400

Necessary when modelling n:m Associations:

Screenshot 2022-10-21 at 13.36.37|400

With 1:1 or 1:n possible but not necessary:

Screenshot 2022-10-21 at 13.36.56|400

Association Class vs Regular Class


Screenshot 2022-10-21 at 13.37.18|500

Unique/Non-Unique


Screenshot 2022-10-21 at 13.37.41|500

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 of A and C is part of B, C is also part of A.
  • Asymmetric: it is not possible for A to be part of B and B to be part of A 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

Screenshot 2022-10-21 at 13.41.11|450

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.

Screenshot 2022-10-21 at 13.42.53|600

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.

Screenshot 2022-10-21 at 13.45.47|450

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: Screenshot 2022-10-21 at 13.46.52|400

With vs Without Generalisation


Screenshot 2022-10-21 at 13.47.13

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.

Screenshot 2022-10-21 at 13.48.48|400

Notation


NameNotationDescription
ClassScreenshot 2022-10-21 at 13.51.48Description of the structure and behaviour of a set of objects.
Abstract ClassScreenshot 2022-10-21 at 13.54.37Class that cannot be instantiated.
AssociationScreenshot 2022-10-21 at 13.55.00Relationship between classes where navigability is unspecified or bidirectional or one directional.
n-ary AssociationScreenshot 2022-10-21 at 13.55.59Relationship between n (here 3) classes.
Association ClassScreenshot 2022-10-21 at 13.56.24More detailed description of an association.
xor RelationshipScreenshot 2022-10-21 at 13.56.47An object of C is in a relationship with A or with B but not both.
Shared aggregationScreenshot 2022-10-21 at 13.57.45Parts-whole relationship (A is part of B)
Strong aggregation (composition)Screenshot 2022-10-21 at 13.58.08Existence-dependant parts-whole relationship (A is part of B)
GeneralisationScreenshot 2022-10-21 at 13.58.34Inheritance relationship (A inherits from B)
ObjectScreenshot 2022-10-21 at 13.58.54Instance of class.
LinkScreenshot 2022-10-21 at 13.59.15Relationship between objects.