OCUP2F 02 Class Diagram
Jump to navigation
Jump to search
Module 4. Class Diagram⌘
Class Diagram⌘
This is structure diagram which presents structure of the designed system at the level of classes, interfaces and relationships - generalizations, associations, dependencies, ...
Element⌘
Metaclass Element
- An element is a constituent of a model.
- All elements are subclasses of Element
- Element can own other elements
- No notation for Element - it is abstract
Relationship ⌘
Relationship class
- Used to interconnect elements
- No notation for Relationship as it is abstract
Directed Relationship ⌘
DirectedRelationship class
- a specialization of a relationship
- source element wants something - a client
- target element offers something - a supplier
Comment⌘
- a textual annotation that can be attached to an element
- may contain information that is useful to a modeler
- can be attached to more than one element
Constraint⌘
- condition or restriction related to an element
- it must always be true
- can be in formal (OCL - Object Constraint Language), programming (e.g. Java), or human language
- syntax:
{ [name :] boolean expression }
Constraint Example⌘
Expression⌘
- Expressions specify values resulting from a computation.
- Examples: xor, else, plus(x,1), x+1
- Opaque Expression specifies the computation of a set of values in UML or any other language.
- Opaque expression may have a language defined e.g. {OCL} i > j and self.size > i
Classifier⌘
- an abstract base class
- describes a set of instances that have features in common
Simple Classifier⌘
- Simple Classifier specifies various kinds of Classifier that do not have complex internal structure.
- Simple Classifiers are:
- Data type
- Signal
- Interface
Data type⌘
- A data type is a type whose instances are identified only by their value - two instances with the same value are indistinguishable (equal).
- A DataType may contain attributes to support the modeling of structured data types.
PrimitiveType⌘
A primitive type defines a predefined data type, without any relevant substructure.
Instances of primitive type:
- Boolean (true, false)
- Integer (..., -1, 0, 1, ...)
- UnlimitedNatural (*, 0, 1, 2, ...) - the value of unlimited is shown using an asterisk ‘*’
- String is a sequence of characters within double quotes e.g. "NobleProg"
- Real
real numbers using floating point representation shown in decimal notation or scientific notation e.g. 8E2
PrimitiveType examples⌘
Enumeration⌘
- An enumeration is a data type whose values are enumerated in the model as enumeration literals.
- Values corresponding to Enumeration Literals are immutable, so any attributes on an Enumeration shall be read-only.
- The Enumeration Literal name is unique within its Enumeration.
- Enumerations can participate in generalization relationships.
Interface⌘
- is a kind of classifier that represents a declaration of a set of coherent public features and obligations
- an interface specifies a contract; any instance of a classifier that realizes the interface must satisfy that contract
- it is just declaration - so it is not instantiable
Provided Interface⌘
- an interface realized by a classifier is its provided interface
- represent the obligations that instances of that classifier have to satisfy
Required Interface⌘
- specify services that a classifier needs in order to perform its function
Interface Example⌘
Structured Classifier⌘
- Describes the internal structure of a classifier and the collaborations that this structure makes possible.
- Structured Classifiers may contain an internal structure of connected elements each of which plays a role.
Structured Classifier Example⌘
Class⌘
- describes a set of objects that share the same specifications of features (attributes and operations)
- is a special classifier
- an object is an instance of a class
Generalization⌘
- relationship between a more general classifier and a more specific classifier
- each instance of the specific classifier is also an indirect instance of the general classifier
- the specific classifier inherits the features of the more general classifier
Generalization Example⌘
Association⌘
- specifies a relationship between instances
- describes a set of tuples whose values refer to typed instances
- declares that there can be links between instances of the associated types
Multiplicity⌘
- specifies how many objects of the opposite class an object can be associated with
- is a range of the minimum and maximum values
- syntax: number or min..max
| Multiplicity | Notation |
|---|---|
| zero | 0 or 0..0 |
| exactly one | 1 |
| zero or one | 0..1 |
| zero or more | 0..* or * |
| one or more | 1..* |
Multiplicity example⌘
Multiplicity - order and uniqueness⌘
- Multiplicity defines a specification of order and uniqueness of the collection elements.
- This option can specify whether the values should be unique and/or ordered.
- ordered: the collection of values is sequentially ordered (default: not ordered)
- unique: each value in the collection of values must be unique, no two values in the collection may be equal (default: is unique)
Aggregation⌘
- shows how something (whole) is composed of parts
- parts can exist separately - can be shared
- precise semantics of aggregation varies by application area and modeler :)
Composition⌘
- a strict form of aggregation
- the whole is the owner of its parts
- parts can not be shared
- the existence of its parts depends on the whole
Aggregation / Composition Example⌘
N-ary association⌘
- if an association has more than two end points (here: ternary association)
- Notation: a rhombus is used as a connection point
Dependency ⌘
- a relationship that signifies that a model element(s) requires other model element(s) for their specification or implementation
- the complete semantics of the depending elements is dependent on the definition of the supplier element(s)
- the modification of the supplier may impact the client model elements
- the semantics of the client is not complete without the supplier
- the type of dependency can be specified by using a keyword or stereotype
Abstract Classifier⌘
- Abstract Classifier has no direct instances.
- The name of an abstract Classifier is shown in italics or in addition, an abstract Classifier may be shown using {abstract} constraint after or below its name.
Feature⌘
- declares a behavioral or structural characteristic of instances of classifiers
- structural feature describes a structure of an instance of a classifier (e.g. property)
- behavioral feature specifies an aspect of the behavior of classifier's instances (e.g. operation)
Property⌘
Property Notation⌘
<property> ::= [<visibility>] [‘/’] <name> [‘:’ <prop-type>] [‘[‘ <multiplicity-range> ‘]’]
[‘=’ <default>] [‘{‘ <prop-modifier > [‘,’ <prop-modifier >]* ’}’]
<visibility> ::= ‘+’ | ‘-‘ | ‘#’ | ‘~’
<prop-modifier> ::= ‘readOnly’ | ‘union’ | ‘subsets’ <property-name>
| ‘redefines’ <property-name> | ‘ordered’ | ‘unordered’
| ‘unique’ | ‘nonunique’ | ‘seq’
| ‘sequence’ | ‘id’ | <prop-constraint>
<inherited-property> ::= ’^’ <property>
Important Property Modifiers⌘
- readOnly means that the Property is read only.
- ordered means that the Property is ordered, i.e., isOrdered = true.
- unordered means that the Property is not ordered, i.e., isOrdered = false.
- unique means that there are no duplicates in a multi-valued Property, i.e., isUnique = true.
- nonunique means that there may be duplicates in a multi-valued Property, i.e., isUnique = false.
- id means that the Property is part of the identifier for the class.
Property = End or Attribute⌘
Navigability⌘
- specifies whether one object can be accessed directly from another
Visibility Example⌘
Operation⌘
- a behavioral feature of a classifier, which specifies name, type, parameters, and constraints
- can have preconditions and postconditions
- can have a type (the type of the return parameter)
[<visibility>] <name> ‘(‘ [<parameter-list>] ‘)’ [‘:’ [<return-type>]
[‘[‘ <multiplicity-range> ‘]’] [‘{‘ <oper-property> [‘,’ <oper-property>]* ‘}’]]
<oper-property> ::= ‘redefines’ <oper-name> | ‘query’ | ‘ordered’ | ‘unordered’
| ‘unique’ | ‘nonunique’ | ‘seq’ | ‘sequence’ | <oper-constraint>
Operation examples⌘
+createWindow (location: Coordinates, container: Container [0..1]): Window +toString (): String +toString(return : String)
INCORRECT:
Sub CalledProcedure(ByRef X As Long, ByVal Y As Long) int addition (int a, int b)
Signals and Receptions⌘
- Signals and Receptions are used to model asynchronous communication between objects.
- A Signal is a specification of a kind of communication between objects in which a reaction is asynchronously triggered in the receiver without a reply.
- The data carried by the communication are represented as attributes of the Signal.
- A Signal is defined independently of the Classifiers handling it.
Reception ⌘
- A Reception is a declaration stating that a Classifier is prepared to react to the receipt of a Signal.
- The name of the Reception matches the name of the Signal, and the parameter of the Reception matches the attribute of the Signal.
- By declaring a Reception associated to a given Signal, a Classifier specifies that its instances will be able to receive that Signal, or a subtype thereof, and will respond to it with the designated Behavior.
Static Feature⌘
- Characteristic relates to the Classifier’s instances may be considered individually (non static), or to the Classifier itself (static).
- Notation: static features are underlined.


























