developing domain models the most important uml model
TRANSCRIPT
The VisionThe Vision
Soft Systems Models
Use Cases
Interaction Models
Class Diagrams
Programs
Databases
BusinessComputing
What is a Domain Model?What is a Domain Model?
• Later we will see that the class diagram in UML is a design for software and databases
• The class diagram is based on a model of the real world which we will call the Domain Model
• Our domain model is a class diagram specified at a level of abstraction that models a real world situation
• We will call this a domain model to distinguish it from the more detailed class diagrams that can be used to generate program code
classes consist ofclasses consist of
• A name, e.g. customer
• Attributes, e.g. name and address
• Operations, e.g. order, pay for goods
Representing classesRepresenting classes
Customer
nameaddress
orderreceive goodspayreturn goods
Invoice
customerIDcustomer addressinvoice linesvattotal
Relationships / AssociationsRelationships / Associations
• Provide lines of communication between classes
• Are used to construct complex systems
Relationship typesRelationship types
• Relationships can fall into any of three basic types
often referred to as the relationship’s Multiplicity.
• One to one
• One to many
• Many to many
• Each end of a relationship on a domain model can
have a note displaying a symbol or number which
describes the kind of relationship
Relationship notationRelationship notation
Notation Meaning
1 One at this end
1..n One or more at this end
3..n Three or more at this end
5 Exactly five at this end
0..n Zero or more at this end
7..10 Seven to ten at this end
One-to-one RelationshipsOne-to-one Relationships
• Modelled by a line between the two classes
• No arrows, so either class may communicate with the
other
• You can label the relationship (but you don’t have to) No label at an end of a relationship indicates a 1
• You may also wish to name the relationship
man womanmarried
Directional relationshipsDirectional relationships
Arrows indicate that one class communicates with
another, but not the other way
canarylittle old lady cateatown
One-to-many RelationshipsOne-to-many Relationships
• These are modelled by a labelled straight line, with a label at the end indicating the “many” end of the relationship
• A label must be used to indicate how many
• No label implies one class at the end of the relationship
• e.g. a player plays for one football team. There are at least 11 players for a given football team.
player team
111..n 111..n
One to many relationshipsOne to many relationships
A customer has zero or more invoices
customer invoice
0..n0..n
One to many relationshipsOne to many relationships
• A juggler has two hands and a hand can hold zero or one ball
juggler hand
22
jugglingBall0..1hold 0..1
Many-to-many RelationshipsMany-to-many Relationships
• These are modelled by a straight line, with a label at each end
• A lubricant may be recommended for one or more engines, and an engine may have one or more lubricants recommended for it
lubricant engine
1..n1..n
recommendation
1..n 1..n
Many-to-many RelationshipsMany-to-many Relationships
• A postman might be bitten by zero or more dogs, and a dog may bite zero or more postmen
postman dog
0..n0..n 0..n0..n
Many-to-many RelationshipsMany-to-many Relationships
• A suitor may court one or more princesses, and a princess may have zero or more suitors
suitor Princess
1..n0..n0..n 1..n
Many-to-many RelationshipsMany-to-many Relationships
• Frogs and princesses have relationships too!
frog Princess
0..11..n 0..11..n
a domain modela domain model
• domain models consist of a number of related classes
patient
doctor
0..n0..n
refer
specialist
0..n
0..n
0..n
0..n
1..n1..n
use
1..n 1..n
treat
A domain modelA domain model
buttonlift
1..n1..n
call
floor
1..2
1..n
1..n
1..n
1..n
service
0..1
0..n0..n
0..1at
1..2
a domain modela domain model
flower Wolf
Grandma
eat
Red Riding Hood
1..n1..n
WoodMan
kill
rescuefetch
talk
a domain modela domain model
shopping home page
product page
1..nshopping
basket page1..n
1..n
1..n
shopping basket
1..n1..n
order1..n1..n
a domain modela domain model
Module
Coursework Submission
Student1..n1..n
1
Lecturer
1..n1..n
Assessment
2
1..n1..n
1..n
exam script
1..n1..n
1..n1..n
2
1..n
Remember Daisy?Remember Daisy?
Daisy: Cow
Colour = BrownPattern = noneWeight = 400kg
Cow
NameWeightPattern
Produce MilkGo “Moo”Eat Grass
ObjectClass
Thelma and MadgeThelma and Madge
Thelma Madge CowName
WeightPattern
Produce MilkGo “Moo”Eat Grass
Daisy
All belong to the class COW
Madge, Silver and DollyMadge, Silver and Dolly
Share some attributes and operations
CowName
WeightPattern
Produce MilkGo “Moo”Eat Grass
HorseName
WeightHeight
RunsJumps
Eat Grass
SheepName
WeightWool colour
Goes “Baah”Produces wool
Eat Grass
New ClassNew Class
AnimalName
Weight
Eat Grass
This class contains all the shared attributes and operations of the three other classes
The concept of inheritanceThe concept of inheritanceIf we were to model sheep, cows and horses in one diagram we may well use the new animal class to make the process much more economical. The diagram would then look like this:
AnimalName
Weight
Eat Grass
Cow
Pattern
Produce milkGo “moo”
Sheep
Wool colour
Produce woolGo “Baah”
Horse
Height
JumpRun
The concept of inheritanceThe concept of inheritance
• By doing this we are saying that the Cow, Horse and Sheep classes can INHERIT all the attributes from the animal class.
• In this instance, the animal class is known as a SUPERCLASS and the Cow, Horse and Sheep classes are SUB-CLASSES
Superclass
Sub-class Sub-class
The concept of inheritanceThe concept of inheritance
• So in addition to the Horse
having Height as an attribute,
it also inherits Name and
Weight.
• And as well as having the
operations Jump and Run, it
also inherits Eat Grass
AnimalName
Weight
Eat Grass
Horse
Height
JumpRun
InheritanceInheritance
• Classes can be arranged in inheritance hierarchies
• A class inherits operations and attributes from its parent
• This is one of the underlying mechanisms for providing for design and code re-use
• We use a special relationship to indicate this on the domain model:
parentchild
Inheritance - exampleInheritance - example
student
coursemodules taken
person
nameaddress
Lecturer
modules taught
Suppose we have already defined the notion of person as an objectWe now want to add a new kind of person - a student
So we make use of the existing person definition, and introduce an inheritance relationshipNow students have the same attributes as person, plus some new ones of their ownAnd likewise, we can create a new type of person, a lecturer, that inherits from person
Relationships are inheritedRelationships are inherited
student
coursemodules taken
Lecturer
modules taught
person
namecompanyaddress
Suppose that we find that person and company share addressWe can split address out into a separate object And then add in some relationships Now if we add in a student And make the student inherit from person Then students have addresses too by inheritance And we can do the same for a lecturer
Inheritance - jugglingInheritance - jugglingjuggleObject
weight
throw()catch()pickUp()drop()
jugglingBall
club
rotationSpeed
ball
diameter
tennisBall
bounce()
egg
smash()
Consider our juggling objects
There are three types of thingto juggle.
And balls can be further refined
So tennis balls can be bounced, thrown, caught, picked up and dropped
Inheritance goes all the way down the hierarchy
Inheritance - enginesInheritance - engines
engine
cylindersname
start()stop()
Diesel Engine
preheat()
Petrol Engine
spark plugs
Steam Engine
boiler
light()
Inheritance - governmentInheritance - government
Government Organisation
tax()elect representatives()
Local Government
Provide Service()
Central Government
Legislate()
Regional Government
Set Transport Policy()
Metropolitan Government
Set Education Policy()
Inheritance - magnitudeInheritance - magnitude
Magnitude
compare()print()
Coordinate
add()subtract()multiply()
Integer
add()subtract()multiply()
Why not push add, subtract, multiply up the hierarchy?
Because, though they have the same name, they do different things!
Multiple inheritanceMultiple inheritance
salt
solvent solution
An object can get operations and attributes from two or more other objects
Problems of multiple inheritanceProblems of multiple inheritance
• Conflict on inherited attributes and methods
• Complexity
• In general avoid it - mostly it can be worked around in better ways (see delegation, later)
Finding inheritanceFinding inheritance
• If two things are similar, are there common aspects (e.g. employee and customer)
• If you want to create something new, is there something similar to inherit from (e.g. web customer might be a special case of customer)
AggregationAggregation
• Objects can be made up of other objects, e.g. a car is
made up of engine, body, transmission and wheels.
• Aggregation hierarchies are used to describe this
• There is no inheritance in an aggregation hierarchy
• We use a special relationship to indicate aggregation
wholepart
Aggregation - exampleAggregation - example
hand
juggler
foot
22
A juggler has hands and feetHands and feet are “part of” a jugglerAnd there are two of each (normally)
Aggregation - lubricantsAggregation - lubricants
lubricant
base oil additive package
dispersant antioxidant vi improverdetergent
Finding aggregationFinding aggregation
• Break complicated objects into their parts
• Build objects out of existing objects
Inheritance and AggregationInheritance and Aggregation
• Are important types of relationships
• Allow developers to re-use existing designs and
implementations
• Adds more meaningful structures
• Reduces the amount of development and design
time that is needed.
DelegationDelegation
• Operations on an object can be delegated to
component objects (e.g. starting a car is delegated to
the engine, which in turn might be delegated to the
starter motor and ignition system)
• Delegation is another way of introducing sharing.
Objects with common components can share the
implementation of those components.
• We shall be looking at how objects call each other in
more detail later
Key PointsKey Points
• Inheritance and aggregation are special types of
relationship
• Inheritance passes attributes and operations
• Aggregation does not pass attributes and operations
• Aggregate objects delegate functionality to their parts
• Inheritance allows for re-use of designs and
implementation
domain modellingdomain modelling
• The principle output of OOAD is the domain model
• The domain model consists of all classes and
relationships
• It defines the static structure of a system
• It evolves and is extended throughout the
development life-cycle
domain modellingdomain modelling
• The domain model will expand and increase in detail as analysis and design progresses
• The first model should only consider real world elements and leave out design and implementation details
• Dynamic modelling will be used to extend the domain model
• Design will add new classes such as interfaces and control classes, and partition the system using concepts such as packages and components
• Implementation will add further detail