Professional Documents
Culture Documents
Class Model
Class Model
Class Model
Language)
What is a Domain Model?
Sale SalesDatabase
amt
vs. Sale
item
Double amt;
Item item;
void print()
What’s the
Identify conceptual classes
from noun phrases
• Vision and Scope, Glossary and Use Cases
are good for this type of linguistic analysis
However:
• Words may be ambiguous or synonymous
• Noun phrases may also be attributes or
parameters rather than classes:
– If it stores state information or it has multiple behaviors,
then it’s a class
– If it’s just a number or a string, then it’s probably
an attribute
From NPs (Noun Phrase) to classes or attributes
Consider the following problem description, analyzed for Subjects, Verbs, Objects:
The ATM verifies whether the customer's card number and PIN are correct.
SC V RO O A OA
If it is, then the customer can check the account balance, deposit cash, and withdraw cash.
SR V OA V O A V OA
Checking the balance simply displays the account balance.
SM OA V OA
Depositing asks the customer to enter the amount, then updates the account balance.
SM V OR V OA V OA
Withdraw cash asks the customer for the amount to withdraw; if the account has enough cash,
SM OA V OR OA V SC V OA
the account balance is updated. The ATM prints the customer’s account balance on a receipt.
OA V SC V OA O
Analyze each subject and object as follows:
Does it represent a person performing an action? Then it’s an actor, ‘R’.
Is it also a verb (such as ‘deposit’)? Then it may be a method, ‘M’.
Is it a simple value, such as ‘color’ (string) or ‘money’ (number)?
Then it is probably an attribute, ‘A’.
Which NPs are unmarked? Make it ‘C’ for class.
Steps to create a
Domain Model
7
Monopoly Game domain model
Larman, Figure 9.28
Class Diagrams
• A Class diagram shows the static structure of the system.
9
Class Diagrams
• Inheritance (generalize/specialize), aggregation
(comprises), and composition (has) relationships are also
captured in this diagram.
10
Class Diagrams
• The class diagram plays a vital role in the transition from
design to construction as it contains sufficient detail to
begin the coding process.
11
Class diagrams
A class diagram helps you visualize the structural or static
view of a system and is one of the most common diagram
types.
12
Class diagrams
– There are typically many class diagrams in a single
model.
13
A very simple class model
• In UML, a class is shown in a class diagram as a rectangle
giving its name
14
What makes a class model good?
• Ultimately, we have two objectives which we aim to meet:
15
In order to meet the objectives:
• Every piece of behaviour which is required of the system
must be able to be provided, in a sensible way, by objects
of the classes we choose
16
Attributes and operations
• Most important are the operations of a class,
which define the ways in which objects may
interact.
• The attributes of a class describe the data
contained in an object of the class
17
UML Class properties:
• Association
• Multiplicity
• Generalization
• Aggregation and composition
• Qualified associations
• Qualified composition
• Derived associations
• Navigability
• Constraints
• Association classes
• Qualifier
18
Associations
• In the same sense that classes correspond to nouns,
associations correspond to verbs.
19
Class A and B are associated if
• an object of class A sends a message to an object of class B
20
Simple association between classes
21
Example
1..* 1
23
Multiplicity
• Association with two objects could be for more than one
class the measure of this is called multiplicity. It describe
in range as below:
• Lower Bound….Bound
24
Generalization
• Important relationship which may exist between classes is
generalization
characteristics.
25
Example:
26
Example :
• The following diagram shows a parent class generalizing a
child class. Implicitly, an instantiated object of the Circle
class will have attributes x_position, y_position and radius
and a method display(). Note that the class "Shape" is
abstract, shown by the name being italicized.
27
CRC cards
• One common way of checking for a good design and
guiding its refinement is to use CRC cards.
28
Creating CRC card
• The name of a class, at the top
• The responsibilities of the class, on the left-hand side
• The collaborators of the class, which help to carry out each
responsibility, on the right-hand side of the card.
29
Aggregation and composition
• Aggregation and composition are kinds of association:
– Instead of just showing that two classes are associated we may
choose to show more about what kind of association this is
is part of
30
Module is a part of an Honours Course
31
Composition
• Composition is a special kind of aggregation which does
impose some further restrictions.
• A stronger form of aggregation - a composite aggregation -
is shown by a black diamond-shaped arrowhead
• In composition association, the whole strongly owns its
parts
– If the whole object is copied or deleted, its parts are
copied or deleted with it
• The multiplicity at the whole end of a composition
association must be 1 or 0..1
– A part cannot be part of more than one whole by
composition
32
Example
Noughts and Crosses
(Tic-Tac-Toe)
33
Example:
• The following diagram illustrates the difference between weak and
strong aggregations.
• An address book is made up of a multiplicity of contacts and contact
groups. A contact group is a virtual grouping of contacts; a contact
may be included in more than one contact group. If you delete an
address book, all the contacts and contact groups will be deleted too; if
you delete a contact group, no contacts will be deleted.
34
Roles
• Often you can read an association name in both directions
(‘is taking’,’is taken by’)
• Message having a task role to play binary association is
shown by thick line and role by thick trainable. The
direction of triangle indicates how to read the association.
• Sometimes, however, it is more readable to have separate
names for the roles that the objects play in the association.
35
Association with no navigability
36
Navigability
• We can put an arrow on one or both ends of the association
line to represent that it is possible for messages to be sent
in the direction of the arrow
37
Example:
38
CASE STUDY
• A product is to be installed to control elevators in a
building with m floors. The problem concerns the logic
required to move elevators between floors according to
the following constraints:
– Each elevator has a set of m buttons, one for each floor. These
illuminate when pressed and cause the elevator to visit the
corresponding floor. The illumination is canceled when the elevator
visits the corresponding floor.
– Each floor, except the first floor and top floor has two buttons, one
to request and up-elevator and one to request a down-elevator.
These buttons illuminate when pressed. The illumination is
canceled when an elevator visits the floor and then moves in the
desired direction.
– When an elevator has no requests, it remains at its current floor
with its doors closed.
• Identify classes and design class diagram of the above
scenario.
39
40
Case Study
• Paragraphs Corporation sells books and CDs using
through online shopping. The customer adds items to her
shopping cart. She may remove items or go to the check-out to
make her purchases at any time. The customer reviews her
purchases, chooses a payment method and pays. A sales
employee at Paragraphs Corporation gets the order and
purchase confirmation from the system, and sends the
electronic order to the warehouse. The warehouse employee
updates the order status. The customer may check the order
status.
• Identify classes and associations between classes.
• Design class diagram for the above case study.
41