You are on page 1of 25

Domain Model &

Class Diagram
Lecture 12 13 14

Domain Modelling
Using UML diagram to construct a
model of the real-world system:
Understand the problem domain.

Model recorded as a simplified class


diagram.
Seamless development:
The same notation is used for analysis and
design.
The design can evolve from the initial
domain model.
1/7/16

CPSC-4360-01, CPSC-5360-01,
Lecture 3

Domain Model Notation


A subset of class diagram model
elements are used.
Class Name

Name
Multiplicity

Attributes

Multiplicity

Association

Class

1/7/16

CPSC-4360-01, CPSC-5360-01,
Lecture 3

Domain Model Notation


Classes represent real-world
entities.
Attributes represent the data held
about entities.
Associations represent relationships
between the entities.

1/7/16

CPSC-4360-01, CPSC-5360-01,
Lecture 3

Case Study 1: Customers and Reservations


Basic business fact: customers make
reservations.

1/7/16

CPSC-4360-01, CPSC-5360-01,
Lecture 3

Defining a Relationship
Give a name to the relationship:
use a verb so that the relationship can be
read as a sentence:
A customer can make many reservations.

How many people make a reservation?


one principal contact whose details are
held;
that principal contact can make more
than one reservation (e.g., by postponing
the time);
the expected
number of diners can be
CPSC-4360-01, CPSC-5360-01,
1/7/16
6
Lecture 3
modelled as an attribute of the

Case Study 1: Tables and Reservation


Is table number an attribute of Reservation?
Better modelled as a separate class:
tables exist even if there are no reservations;
other attributes of tables, e.g., size, can be stored.

1/7/16

CPSC-4360-01, CPSC-5360-01,
Lecture 3

Use of Constraints
Not all domain properties can be
shown graphically:
e.g., it should be impossible to doublebook a table.

Constraints add information to


models:
written in a note connected to the model
element being constrained.

1/7/16

CPSC-4360-01, CPSC-5360-01,
Lecture 3

Correctness
How do we know when a domain
model is complete?
we don't: there are lots of plausible
models in most cases.

Domain modelling is not an end in


itself, but a guide to further
development.
Realizing use cases tests the domain
model, and will usually lead to
refinements.
1/7/16

CPSC-4360-01, CPSC-5360-01,
Lecture 3

Class Diagrams
Gives an overview of a system by
showing its classes and the
relationships among them.
Class diagrams are static
they display what interacts but not
what happens when they do interact

Also shows attributes and


operations of each class
Good way to describe the overall
architecture of system components

Class Diagram Perspectives


We draw Class Diagrams under three
perspectives
Conceptual
Software independent
Language independent

Specification
Focus on the interfaces of the software

Implementation
Focus on the implementation of the software

Classes Not Just for Code


Name
TariffSchedule
zone2price
getZones()
getPrice()

Attributes
Operations

A class represent a concept


A class encapsulates state (attributes) and behavior
(operations).
Each attribute has a type.
The class name is the only mandatory information.

UML Class Notation


A class is a rectangle divided into three
parts

Class name
Class attributes (i.e. data members, variables)
Class operations (i.e. methods)

Modifiers

Private: Public: +
Protected: #

Lines or arrows between classes indicate


relationships
Association

A relationship between instances of two classes, where one


class must know about the other to do its work, e.g. client
communicates to server
indicated by a straight line or arrow

Aggregation

An association where one class belongs to a collection, e.g.


instructor part of Faculty
Indicated by an empty diamond on the side of the collection

Composition

Strong form of Aggregation


Lifetime control; components cannot exist without the
aggregate
Indicated by a solid diamond on the side of the collection
Arm-body

Inheritance

An inheritance link indicating one class a superclass


relationship, e.g. bird is part of mammal
Indicated by triangle pointing to superclass

Binary Association
Binary Association: Both entities Know About each other

myB.service();

myA.doSomething();

Optionally, may create an Associate Class

Unary Association
A knows about B, but B knows nothing about A

myB.service();

Arrow points in direction


of the dependency

Aggregation
Aggregation is an association with a collection-member relationship

void doSomething()
aModule.service();

Hollow diamond on
the Collection side
No sole ownership implied

Composition
Composition is Aggregation with:
Lifetime Control (owner controls construction, destruction)
Part object may belong to only one whole object

members[0] =
new Employee();

delete members[0];

Filled diamond on
side of the Collection

Inheritance
Standard concept of inheritance

Base Class

Derived Class
class B() extends A

UML Multiplicities
Multiplicity of attributes
Links on associations to specify more details about the relationship
Multiplicities

Meaning

0..1

zero or one instance. The notation n . . m


indicates n to m instances.

0..* or *

no limit on the number of instances


(including none).

exactly one instance

1..*

at least one instance

Sataic Attribute Underline

Basic Level Class


Diagram

Detailed Level Class


Diagram

UML Class Example

Association Details
Can assign names to the ends of the
association to give further
information
Team

Employee

-group

-members: Employee

-individual
1
*

-Name : string
+ID : long
#Salary : double
-adfaf : bool
+getName() : string
+setName()
-calcInternalStuff(in x : byte, in y : decimal)

Constraints
PreConditions must be true before a
method is executed

You might also like