Top Banner
Developing Domain Models Developing Domain Models The most important UML model
54
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Developing Domain Models The most important UML model.

Developing Domain ModelsDeveloping Domain Models

The most important UML model

Page 2: Developing Domain Models The most important UML model.

The VisionThe Vision

Soft Systems Models

Use Cases

Interaction Models

Class Diagrams

Programs

Databases

BusinessComputing

Page 3: Developing Domain Models The most important UML model.

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

Page 4: Developing Domain Models The most important UML model.

classes consist ofclasses consist of

• A name, e.g. customer

• Attributes, e.g. name and address

• Operations, e.g. order, pay for goods

Page 5: Developing Domain Models The most important UML model.

Representing classesRepresenting classes

Customer

nameaddress

orderreceive goodspayreturn goods

Invoice

customerIDcustomer addressinvoice linesvattotal

print

Page 6: Developing Domain Models The most important UML model.

Relationships / AssociationsRelationships / Associations

• Provide lines of communication between classes

• Are used to construct complex systems

Page 7: Developing Domain Models The most important UML model.

RelationshipsRelationships

dog bites postman

man orders meal

driver car

Page 8: Developing Domain Models The most important UML model.

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

Page 9: Developing Domain Models The most important UML model.

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

Page 10: Developing Domain Models The most important UML model.

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

Page 11: Developing Domain Models The most important UML model.

Directional relationshipsDirectional relationships

Arrows indicate that one class communicates with

another, but not the other way

canarylittle old lady cateatown

Page 12: Developing Domain Models The most important UML model.

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

Page 13: Developing Domain Models The most important UML model.

One to many relationshipsOne to many relationships

A customer has zero or more invoices

customer invoice

0..n0..n

Page 14: Developing Domain Models The most important UML model.

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

Page 15: Developing Domain Models The most important UML model.

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

Page 16: Developing Domain Models The most important UML model.

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

Page 17: Developing Domain Models The most important UML model.

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

Page 18: Developing Domain Models The most important UML model.

Many-to-many RelationshipsMany-to-many Relationships

• Frogs and princesses have relationships too!

frog Princess

0..11..n 0..11..n

Page 19: Developing Domain Models The most important UML model.

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

Page 20: Developing Domain Models The most important UML model.

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

Page 21: Developing Domain Models The most important UML model.

a domain modela domain model

flower Wolf

Grandma

eat

Red Riding Hood

1..n1..n

WoodMan

kill

rescuefetch

talk

Page 22: Developing Domain Models The most important UML model.

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

Page 23: Developing Domain Models The most important UML model.

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

Page 24: Developing Domain Models The most important UML model.

Other types of RelationshipOther types of Relationship

Inheritance and Aggregation

Page 25: Developing Domain Models The most important UML model.

Remember Daisy?Remember Daisy?

Daisy: Cow

Colour = BrownPattern = noneWeight = 400kg

Cow

NameWeightPattern

Produce MilkGo “Moo”Eat Grass

ObjectClass

Page 26: Developing Domain Models The most important UML model.

Thelma and MadgeThelma and Madge

Thelma Madge CowName

WeightPattern

Produce MilkGo “Moo”Eat Grass

Daisy

All belong to the class COW

Page 27: Developing Domain Models The most important UML model.

IntroducingIntroducing

Silver

Horse

NameWeightHeight

RunsJumps

Eat Grass

Page 28: Developing Domain Models The most important UML model.

andand

Dolly

Sheep

NameWeight

Wool colour

Goes “Baah”Produces wool

Eat Grass

Page 29: Developing Domain Models The most important UML model.

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

Page 30: Developing Domain Models The most important UML model.

New ClassNew Class

AnimalName

Weight

Eat Grass

This class contains all the shared attributes and operations of the three other classes

Page 31: Developing Domain Models The most important UML model.

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

Page 32: Developing Domain Models The most important UML model.

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

Page 33: Developing Domain Models The most important UML model.

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

Page 34: Developing Domain Models The most important UML model.

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

Page 35: Developing Domain Models The most important UML model.

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

Page 36: Developing Domain Models The most important UML model.

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

Page 37: Developing Domain Models The most important UML model.

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

Page 38: Developing Domain Models The most important UML model.

Inheritance - enginesInheritance - engines

engine

cylindersname

start()stop()

Diesel Engine

preheat()

Petrol Engine

spark plugs

Steam Engine

boiler

light()

Page 39: Developing Domain Models The most important UML model.

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

Page 40: Developing Domain Models The most important UML model.

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!

Page 41: Developing Domain Models The most important UML model.

Multiple inheritanceMultiple inheritance

salt

solvent solution

An object can get operations and attributes from two or more other objects

Page 42: Developing Domain Models The most important UML model.

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)

Page 43: Developing Domain Models The most important UML model.

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)

Page 44: Developing Domain Models The most important UML model.

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

Page 45: Developing Domain Models The most important UML model.

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)

Page 46: Developing Domain Models The most important UML model.

Aggregation - lubricantsAggregation - lubricants

lubricant

base oil additive package

dispersant antioxidant vi improverdetergent

Page 47: Developing Domain Models The most important UML model.

Aggregation - PathwaysAggregation - Pathways

Pathway

Module

Lecture Assessment

Page 48: Developing Domain Models The most important UML model.

Finding aggregationFinding aggregation

• Break complicated objects into their parts

• Build objects out of existing objects

Page 49: Developing Domain Models The most important UML model.

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.

Page 50: Developing Domain Models The most important UML model.

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

Page 51: Developing Domain Models The most important UML model.

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

Page 52: Developing Domain Models The most important UML model.

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

Page 53: Developing Domain Models The most important UML model.

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

Page 54: Developing Domain Models The most important UML model.

TutorialTutorial

• Working in groups we will develop a number of domain models and compare the results