Professional Documents
Culture Documents
and Design
Chapter 2-Part II
Structural Model:
Class/Object diagram
Recall
The UMLThe why? and the principle of
modeling
The diagrams
Functional Model
Essential/system usecase
Use case components; Actors,Use
cases,Boundary
And Relationship
Introduction
Modelling a system involves identifying the
Cont
A class is a definition of objects
Cont
Class diagrams are widely used to
Cont
Class diagrams model class structure
Common Uses
Class diagrams are used to model the static
system
Cont
The UML was designed with
11
Cont
To start with class modeling, identify
Cont
13
cards)
are a brainstorming tool used in the design
of object-oriented software.
are typically used when first determining
which classes are needed and how they will
interact.
CRC are an index card on which one records
the responsibilities and collaborators of
classes, thus the name, which stands for
Class-Responsibility-Collaboration.
14
Cont
A class responsibility collaborator model is
objects,
a responsibility is something that a class
Cont..
CRC cards are usually
the class.
The names of other
classes with which the
class will collaborate
to fulfill its
responsibilities.
Cont
Although CRC cards were originally
Basic steps
Brainstorm with SME
Iteratively do the following
Find classes
Find responsibilities
Define collaborators
Objects
An object is simply a real-world thing or concept
Three essential aspects of objects are:
An object has an identity
Can have a name or can be anonymous
An object has state
the names of the various properties that describe the
object (attributes) and also the value of those
attributes
An object has behaviour
represented by functions (or methods) that use or
change the values of the objects attributes
An object is an instance of a class
20
Classes
Classes are the most important building block
developing
represent software things, hardware things, and
even things that are purely conceptual
Well-structured classes have crisp boundaries
operations
Name
Every class must have a name to distinguish
Customer
22
Attribute
An attribute is a named property of a class
(a)
Or, we can further specify an attribute by stating its
type and possibly a default initial value (b)
Customer
name
address
phone
birthdate
(a)
24
Wall
height : Float
width : Float
thickness : Float
isLoadBearing : Boolean
= false
(b)
Operation
An operation is the implementation
names (a)
We can further specify an operation stating its signature
(b)
including the name, type and default value of all
parameters and (in case of functions) a return type
(a)
26
Customer
TemperatureSensor
add()
remove()
edit()
reset()
setAlarm(t :
Temperature)
value() :
Temperature
(b)
Cont
Attributes define the properties
of the objects:
every instance of the class has the
same attributes
an attribute has a data type
an attribute has visibility (private,
protected, public)
the values of the attributes may differ
among instances
27
Cont
Operations define the behavior of the
objects
oaction performed on or by an
object
oavailable for all instances of the
class
omethods/operations has visibility
(private, protected, public)
oneed not be unique among classes
Cont
29
HINTS!
When we model classes, a good starting point is
to specify the responsibilities of the things in our
vocabulary
A class may have any number of responsibilities
We do not want any one class to have too many or
A simple example
On-line Bookstore Review
a web application that can be accessed by the
stores registered customer, whereby each
customer can review one or more books sold in the
book store
The process: Each registered customer has an account that is used to
Things that are found in the problem: The process: Each registered CUSTOMER has an ACCOUNT that is
Account
Used to keep the customers ID and password for verifying
that the customer is a registered customer
Also keeps additional information, i.e. e-mail address
Customer
Used to keep information about the customer, such as
customers name, ID, address etc
Book
Used to keep the relevant information on the book that is
crucial to customers review, i.e. book title, author, rating
Review
Used to assign ratings to book reviewed (with 1 being the
lowest and 5 the highest)
Used to compute the average rating for each book that
has been reviewed
33
Account
Attributes: emailAddress, ID, password
Operations: verifyPassword()
Customer
Attributes: CustName, CustAddress, CustID etc
Operations: NONE
Can choose not to show the attributes when modelling the class
as they are not relevant to the given problem
Book
Attributes: title, author, rating
Operations : NONE
Review
Attributes: NONE
Operations: assignRatings(rating : Int), computeAvgRating() :
double
34
Book
title :
String
author:
String
rating:
Float
Review
Customer
35
assignRating(rating : Int)
computeAvgRating() :
Double
Summary
Attributes, operations and responsibilities are
Relationships
Relationships
A relationship is, a general term, covering
Cont
When we build abstractions, we will
number of ways
must
39
40
Dependency
A dependency is a using relationship
Cont
To model dependency
Create a dependency pointing
44
Course
Generalization
A generalization is a relationship
Cont
It supports polymorphism
An operation of the child that
47
ParentClass
ChildClass
attributes
operations
48
Rectangle
corner :
Point
Circle
Polygon
radius : Float
points : List
display()
51
Association
An association is a structural relationship
same class
Binary association
connects exactly two classes
N-ary association
connects more than two classes
52
53
to associations: Name
An association can have a name to
Person
name direction
Works for
association
54
Company
Role
When a class participates in an association,
Person
employee
employer
role name
55
Company
Multiplicity
It is important to state how many objects may be
Person
56
1..*
employee
*
employer
Company
Aggregation
is a whole-part relationship within which one or
whole
Company
1
aggregation
part
57
*
Department
Association Classes
Sometimes in an association between two
classes, the association itself might have
properties
In the UML, youll model this as an association
class, which is a modeling element that has
both association and class properties
It is used to model an association that has
1..*
employer
employee
association class
Job
description
dateHired
salary
59
Person
1..*
title:
String
BookAndAuth
or
role: String
60
Book
(association): -
61
multiplicity
If one of the classes in an association is
structurally or organizationally a whole
compared with the classes at the other
end that look like parts, use an
aggregation
If theres a many-to-many relationship
between two classes, use association class
(if possible)
Modelling Relationships
When modelling relationships in the UML
Use dependencies only when the relationship is not
structural
Use generalization only when the relationship is an
is-a-kind-of or inheritance relationship
Beware of introducing cyclical generalization relationships
A simple example
On-line Bookstore Review
a web application that can be accessed by the
stores registered customer, whereby each customer
can review one or more books sold in the book store
The process given: Each registered CUSTOMER has an ACCOUNT that is used
problem: Account
Password
Customer
Book
Review
EditorialReview
64
Cont
Each of these things can form
Password
Used to check that the password entered is
valid (more than 8 characters and consists of
combination of text and numbers)
Customer
Used to keep information about the customer,
such as customers name, ID, address etc
Book
Used to keep the relevant information on the
book that is crucial to customers review, i.e.
book title, author, rating
66
Cont
Review
Divided into sub-classes: CustomerReview
and EditorialReview
CustomerReview
Used to assign ratings to book reviewed (with
1 being the lowest and 5 the highest) by
customer
Used to compute the average rating for each
book that has been reviewed by customer
EditorialReview
Used to store editors review
67
Account
Attributes: emailAddress(string), ID(string), passwd(Password)
Operations: verifyPassword(p: Password)
Password
Attributes: passwd(string)
Operations: checkPassword()
Customer
Attributes: CustName, CustAddress, CustID etc
Operations: NONE
Can choose not to show the attributes when modeling the class
as they are not relevant to the given problem (put NONE for
both)
Book
Attributes: title, author, rating
Operations : NONE
68
Review
Attributes: NONE
Operations: NONE
CustomerReview
Attributes: NONE
Operations: assignRatings(rating : Int),
computeAvgRating() : double
EditorialReview
Attributes: NONE
Operations: NONE
69
Association
A customer can open 1 account and an
EditorialReview
Book
has
title :
String
Customer
writes
1
1
opens
1
Review
is written by
CustomerReview
1..*
assignRating(rating : Int)
computeAvgRating() :
Double
Account
emailAddress : string
ID : string
passwd : Password
72
verifyPassword(p :
Password)
Password
pass : String
checkPasswor
Summary
Plain, unadorned dependencies,
73
Cont
Dependencies, generalizations
Example
Littlesand, Pebblesea and Mudport are three charming
resorts on the South Coast which are very popular
with tourists, since they score well on beach rating
and hours of sunshine for the area. All three resorts
have a large number of places to stay, ranging from
one-room guest house to the exclusive Palace Hotel at
Pebblesea. The local tourist board wants to set up a
central system to deal with room bookings in the area.
76
77
Resort Class
Used to store information on the resort such as name,
description, beach rating, hours of sunshine etc
Used to perform operations such as updating the
beach rating and updating the hour of sunshine etc
Attributes:
name (string)
description (string)
beach rating (double) hour of sunshine (double)
Operations:
update beach rating
update hours of sunshine
Find the relationships between the classes: All three Resorts have a large number of places
to stay
Places to stay is a part of Resorts, with Resort
being the whole : AGGREGATION
A resort can have 1 or many places to stay
All three resorts have a large number of places
to stay, ranging from one-room guest house to the
exclusive Palace Hotel at Pebblesea
Places to stay consists of guest houses and
hotels, with Places to stay being the parent and
the other two, the child : GENERALIZATION
78
1..*
Place_to_Stay
1..*
Room
1..*
0..*
Booking
1..*
Hotel
80
Guest_House
1..*
Tourist
Resort
name : String
description : String
beach_rating : Double
hours_of_sunshine: Double
update_beach_rating (r :
Double)
update_hours_of_sunshine (h :
Double)
81
82
Object diagrams
Object Diagrams
Object diagrams model the instances of
The object may have a name that appears before the colon,
for an object.
Each attribute defined for the given class has a
specific value for each object that belong to that class.
85
Object : Class
: Class
attribute1 = value
attribute2 = value
attribute1 = value
attribute2 = value
named
object
anonymous
object
Author
name : String
wrote
title : String
rating: Double
published by
Publisher
name : String
87
: Book
: Author
name : Margeret Mitchell
wrote
published by
AW: Publisher
name : Hawthorne
Object diagram
88
: Book
: Author
name : Tim Burton
wrote
published by
AW: Publisher
name : Barnes
Object diagram
89
Exercise
An international airport requires a system to keep track of flight details for
customers. For each flight the system needs to store the flight number,
destination, departure time, departure gate, airline and flight cost. Some
flights are direct flights, i.e. they fly non-stop to the destination and some fly
via another airport to their destination. We will call these flights indirect
flights. In this case the flight stops at an airport en route to its destination to
refuel. In the case of indirect flights information regarding the transit airport
must also be stored. The flight cost is calculated to be the cost charged by
the airline per customer plus a percentage of this amount (the profit_rate).
In the case of indirect flights an additional levy must be added to this
amount per customer in order to cover refuelling levies at the transit airport.
Furthermore, on some flights additional passengers can board the plane at
the transit airport. The system needs to keep track of whether boarding will
take place at the transit airport or not. The system also needs to store
details of the aircraft used for a flight. The aircraft make, model and
capacity (number of passengers that it can carry), must be stored for each
aircraft.