Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 1
Class Diagrams (Relational Elements)
Generalisation, Specialisation
DefinitionInheritance is a relation between superclasses and subclasses whichenables attributes and operations of a superclass to become accessibleto its subclasses.
Description• superclass/subclass
• Discriminator denotes the aspect relevant for hierarchical structuringof the properties.
• Partition is an entirety of subclasses based on the same discriminator.
Notation
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 2
Different views of generalisation:
• conceptual view:all instances of a subclass are also instances of superclass
• specification and implementation views:imply a specification of the operations that must be supportedby its subclass
Multiple classification
• Multiple classification allows multiple types for an object(not supported in Java and in C++)
legal combinations of subtypes: (Female, Patient, Nurse),(Male, Physiotherapist), (Female, Patient), (Female, Doctor, Surgeon)
illegal combinations: (Patient, Doctor), (Male, Doctor, Nurse)
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 3
Multiple InheritanceProblems:1. Name collision: two or more different superclasses use
the same name for some of their propertiessolution: address their property in a fully qualified way
2. Repeated inheritancesolution: superclass is not replicated
Person
Teacher Researcher
Professor
WaterVehicle
draughtdisplacement
WindpoweredVehicle
minWindForcemaxWindForce
Vehicle
namemanufacturer
MotorVehicle
fuelTypepower
SailingBoat
surfaceOfSailsnumberOfSails
{overlapping}
Overlapping versus Disjoint
� It is acceptable for one class to specialiseboth the overlapping subclasses of Boat!
• Overlapping
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 4
WaterVehicle
draughtdisplacement
WindpoweredVehicle
minWindForcemaxWindForce
Vehicle
namemanufacturer
MotorVehicle
fuelTypepower
SailingBoat
surfaceOfSailsnumberOfSails
{disjoint}
� This specialisation is not correct!An object cannot be an instance of bothWaterVehicle and WindpoweredVehicle!
• Disjoint
Constraints on generalisation:• overlapping• disjoint• complete• incomplete
Superclass
Subclass1 Subclass2
{incomplete}
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 5
Association
DefinitionAssociation describes a connection between classes.
Description• Links are instances of an association.• Recursive association• Aggregation, composition
Notation• Multiplicity of an association specifies the number of objects of the
opposite class with which an object can be associated.• Roles• Constraints
Class A Class Brole a role b
1 *
<<Stereotypes>>RelationName{Constraint/TaggedValues}
Multiplicity
�
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 6
Example
• Examples of multiplicity specifications:10, 10..43, 70..* (default)*1..*0..3, 7, 9..*
Implementation: assign appropriate reference attributes to theinvolved classes.
Company
nameaddress
Employee
nameaddressstaffNo*11
employeeemployer
*
employs
works for
�
�
• role name• multiplicity
Personal Customer
creditCard#
Customer
nameaddress
creditRating():String
Order
dateReceivedis Prepaidnumberprice
dispatch()close()
1
Product
Order Line
quantity:Integerprice:MoneyisSatisfied:Boolean
*
1
*11
*
1
line items*
* 1
Corporate Customer
contactNamecreditRatingcreditLimit
remind()billForMonth(Integer)
Employee
0..1
*
0..1
*
sales rep
{if Order.customer.creditRatingis "poor" then Order.isPrepaidmust be true}
{creditRating() == "poor"}
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 7
• Interface for an Order class:
class Order {public Customer getCustomer() ;public Set getOrderLines() ;…
• Implementation model
class Order {private Customer _customer ;private Set _lineItems ;
class Customer {private Set _orders ;
Personal Customer
creditCard#
Customer
nameaddress
creditRating():String
Order
dateReceivedis Prepaidnumberprice
dispatch()close()
1
Product
Order Line
quantity:Integerprice:MoneyisSatisfied:Boolean
*
1
*11
*
1
line items*
* 1
Corporate Customer
contactNamecreditRatingcreditLimit
remind()billForMonth(Integer)
Employee
0..1
*
0..1
*
sales rep
{if Order.customer.creditRatingis "poor" then Order.isPrepaidmust be true}
{creditRating() == "poor"}
• navigability– unidirectional– bidirectional
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 8
Dependency Relations
DefinitionDependency is a relation between two model elements whichshows that a change in one element requires a change in the other.
Description• Influences the order of compilation.
Notation
dependent independent
Example
• Class uses an interface of another class.
• Class is dependenton another class.
• Operation is dependenton a class.
• Package is dependent on another package.
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 9
• parameter reference
• creation of object
☛ do not imply an associationthey are modelled with dependencies !
Recursive Associations
DefinitionRecursive associations are associations in which only one class isinvolved.
Example
Employee
namestaffNoroomNo
office clerk
*
manager 1
leads
reports to�
�
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 10
Attributed Association
DefinitionAttributed association is a model element which has both the propertiesof a class and an association.
Description• Association class
Notation
Class A
Association
Class BAssociation
Association class
Enterprisename
address
Employmentfrom:Date
to:Date
Employeename
address
1..* *
Association attributes
Example•Two involved objects may at most have one relation with each other.
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 11
Class A
Associationclass
Class B
Class A Class B
Class C
1 1
1..*
*1..*
*
promoting an association classto a full class
Enterprise Employee
Employmentfrom: Date
to: Date
1
* 1..*
1
• Promoting an association class to a full class enablesan Employee to have more than one Employment withthe same Enterprise.
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 12
Skill
Competency
Employee* *
• Employee is not allowed to have more than one Employmentwith the same Enterprise
☛ use an association class• Employee is allowed to have more than one Employment
with the same Enterprise☛ use a full class
• Employee has one competency in the same skill☛ use an association class
Association Constraints
• Ordered association{ordered}{ordered by contract date}
Employee
nameaddress
1
{disjoint periods ofemployment}
Enterprise
nameaddress
Employment
from:Dateto:Date1..*
1
has
11
has
*
�
�
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 13
Qualified Associations
DefinitionA qualified association is an association in which qualifying attributesare used to subdivide the referenced set of objects into partitions, whereeach partition may occur only once.
Description• UML counterpart to the dictionary
Notation and Example
• Multiplicity always refers to one partition.
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 14
Interface for the class Enterprise:
class Enterprise {public Employee getEmployee(String anInitial) ;public void addEmployee(String anInitial, String name) ;private map _Employee ;…
}
Derived Associations
DefinitionDerived association is an association which is calculated when required.
Description• Concrete object relations are derived from the values of other
object relations and their objects.
Notation and Example
employer 1
*
Enterprise Department
1 *
Employee
*
1
/works for*
1
employer
1 *belongs to
department
*
1
works in
�
�
�
{Employee.employer =Employee.department.employer}
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 15
N-ary Associations
DefinitionMore than two association rules are involved.
Description, Notation and Example
Train1 Feb, T11 Feb, T2
PassangerJohn MrMark DrJoana Ms
SeatC1, S1C1, S2
• Here, it is possible to navigate to an association not coveredby the original association occurrences.
Train
datetrain
Passanger
nametitle
1..*
1
Seat
carraigeNoseatNo
1..*1
1..*
1..*
1..*1
1..*
1
1..*
1..*
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 16
• Multiple Association
• N-ary associations can be transformed into normal associations.
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 17
Directed Associations
DefinitionDirected association is an association in which you can directlynavigate from one of the involved association roles to the other,but not vice versa.
Notation• Multiplicity and role names are relevant on the side of the association
towards which navigation is possible.
Example
Person Car0..*
is taking
5
�
Aggregation
DefinitionAggregation is an association in which the involved classesrepresent an entirety-part hierarchy.
Description• Propagation of operations• Composition
Notation
PartEntiretyconsists of
1
�
* BankAccountAddress
Customer
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 18
Composition
DefinitionComposition is a strict form of aggregation, in which the partsare existence-dependent on the entirety.
Description• Cardinality on the side of the aggregate can only be 1.• Each part is part of exactly one composition object.
Notation
PartEntirety
Existence-DependentPart
Aggregation
Composition
Constraints
DefinitionConstraint is an expression which restricts the possiblecontents, states or the semantics of a model element.
Description• legal set of values of an attribute• pre- or postconditions for messages or operations• special context for messages or relationships• specific order• chronological condition...
Notation{constraint}dependency relationnote
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 19
Example
• Dependency
• Consistency
Project
Employee
has consistsof
{subset}
1 1..*
Customer
Invoice Contract
1
0..*
1
0..*
has
based on
receives
�
�
�
project Leader projectMembers
1
Invoiceself.contract.customer = self.customer
• OR
• Values
PersonDomesticaddress
Foreignaddress
has
has�
�
{or}
*
*
Rectanglea {a>0}b {b>0}
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 20
• Order
• Formulae
Person
lastNamefirstName
NameList
1 1..*
contains
{ordered:lastName} 1..*1
Person
birthDate:Date/age {age=today-birth}
Person
birthDate:Date/ age
{/age=today-birthDate}
�
• Enumerationcolour : {red, blue, green}
Responsibility?
Class ShoppingSpree {private Vector participantSet ;public void addParticipant(Person : participant) {
if (participant.age > 65) {participantSet.addElement(participant) ;
}}
...}
Person
ageShoppingSpree
1 1..*
{participant.age>65}
participants1..*
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 21
Tagged Values
DefinitionTagged values are keyword/value pairs which extend the semantics ofindividual model elements.
Description• influence code generation
– abstract for classes and operations– readonly for attributes– private for attributes and operations– obsolete– information on author, version number
Notation
Examples{private}{Author=Tara King}{transient}{persistent}
GeomFigure{abstract Version=1.3}
visible:Boolean {readonly}display() {abstract}remove() {abstract}getPosition(): PointsetPosition(p: Point)
setPos(x,y) {obsolete}
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 22
Stereotypes
DefinitionA stereotype is used as a means of specifying that amodelling element conforms to the well understoodpattern of behaviour.
Description• specify possible usage contexts of a class, a relationship
or a package• model element can be classified with an arbitrary number of
stereotypes• code generation
Types of stereotypes:• decorative• descriptive• restrictive• redefining
Notation
Examples• meaning of a class in the application architecture:<<domain class>>
<<model>>, <<view>>, <<controller>>,<<enumeration><overlapping>>, <<disjoint>>, <<implements>>, <<include>>,<<extend>>
Customer
<<actor>>Customer
<<actor>>Customer
<<actor>><<boundary>>
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 23
<<DomainClass>>Circle
positionvisible
display()remove()
<<Information>>isVisible()
<<AttributeAccess>>getPosition()
setPosition(newPos)
Notes
DefinitionNotes are comments to a diagram or an arbitrary element in a diagram,without any semantic effect.
Descriptioninformation on: development state,
version of a class,developer responsible for the class or its lastmodificationproject management...
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 24
invPosition
quantityitemunitPrice
total
Invoice
invPositions:Set
sumPositions()sumVAT()
1 *1 *
"This example is inJava"
Notation and Example
Packages
DefinitionPackages are collections of model elements which are used tostructure the entire model into smaller units.
Descriptions
• built on the basis of logical or physical relationshipsPackageName::ClassName
• <<global>> all packages in the system have a dependencyto this package•
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 25
Notation and Example
☛ dependencies between packages are not transitive
• generalisation: a package must conform to the interface ofthe general package
Object-Oriented Methods, School of Computer Science and IT, University of Nottingham 26
Refinement or Realisation Relations
Definition• Refinement relations are relations between similar elements of
different degrees of detail.• Realisation relations are relations between interface and its
implementation.
DescriptionRefinement• analysis / design version of a model element• clean / optimised version of a model element
Example
String
isEqual(String):BooleanisGreater(String):Booleanlength():Integer
<<interface>>Sortable
isEqual(object):BooleanisGreater(Object):Boolean
Tariffing Tariffing1
Performanceoptimised