Professional Documents
Culture Documents
Lect 12 Class Diagram
Lect 12 Class Diagram
Lect 12 Class Diagram
Language)
What is a Domain Model?
amt
vs. Sale
item
Double amt;
Item item;
void print()
What’s the
Domain Model
Relationships
Conceptual Class
Domain Model
lasses,
Diagramattributes, associations
Define terms
Domain
Use Case Model Glossary
objects
Functional Requirements
Interaction Diagrams
Dynamic Behavior
What do you learn about when and how to create these models?
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 OA A
O
If it is, then the customer can check the account balance, deposit cash, and withdraw cash.
SR V OA V OA V O
A
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 A
O
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.
Verbs can also be classes, for example:
Deposit is a class if it retains state information
Steps to create a
Domain Model
• Identify candidate conceptual classes
• Draw them in a UML domain model
• Add associations necessary to record
the relationships that must be retained
• Add attributes necessary for information to be
preserved
• Use existing names for things,
the vocabulary of the domain
Monopoly Game domain model
(first identify concepts as classes)
8
Monopoly Game domain model
Larman, Figure 9.28
Class Diagrams
• A Class diagram shows the static structure of the system.
10
Class Diagrams
• Inheritance (generalize/specialize), aggregation
(comprises), and composition (has) relationships are also
captured in this diagram.
• Class attributes and their data types are identified here, as
are the operations and their return types.
• Visibility is indicated by +, #, or - for public, protected, or
private.
11
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.
• It is often used to partition responsibilities among the
project team members, and to guide and measure the
construction process.
12
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.
– Class diagrams show the relationships among and
details about each class.
– Class diagrams are also the foundation for component
and deployment diagrams.
13
Class diagrams
– Rose automatically creates a Main class diagram in the
logical view.
– There are typically many class diagrams in a single
model.
– It shows how a system is structured rather than how it
behaves.
14
A very simple class model
• In UML, a class is shown in a class diagram as a rectangle
giving its name
15
What makes a class model good?
• Ultimately, we have two objectives which we aim to meet:
16
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
17
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
18
UML Class properties:
• Association
• Multiplicity
• Generalization
• Aggregation and composition
• Qualified associations
• Qualified composition
• Derived associations
• Navigability
• Constraints
• Association classes
• Qualifier
19
Associations
• In the same sense that classes correspond to nouns,
associations correspond to verbs.
• They express the relationship between classes.
20
Class A and B are associated if
• an object of class A sends a message to an object of class B
22
Example
1..* 1
24
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
25
Generalization
• Important relationship which may exist between classes is
generalization
characteristics.
26
Example:
27
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.
28
CRC cards
• One common way of checking for a good design and
guiding its refinement is to use CRC cards.
• CRC stands for Classes, Responsibilities, Collaborations.
29
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.
30
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
31
Module is a part of an Honours Course
32
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
33
Example
Noughts and Crosses
(Tic-Tac-Toe)
34
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.
35
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.
36
Association with no navigability
37
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
38
Qualified associations
• Occasionally it is helpful to give finer detail about an
association than we have so far.
• Square is identified relative to the board it’s on by
attributes row and column, each taking a value
between 1 and 3
39
Qualified composition
• In fact we can combine the qualified association notation
with the other adornments on associations
• For example, we can add back the information that this
particular association is a composition
40
Derived associations
• Derived association exists automatically once we have
implemented the main association
• A derived association as shown using a slash in front of its
name
• The black triangles indicate which direction of the
association the name describes.
41
Constraints
• A constraint is a condition that has to be satisfied by any
correct implementation of a design
• The formal constrains can be written in OCL, the Object
Constraint Language (developed by IBM)
• OCL is intended to be
– Formal, so that constraints written in it are unambiguous
42
• The xor constraint is not written in OCL, it’s a special
predefined constraint which is part of UML
43
Association classes
• Association is a class by itself that has its own properties.
44
Example (Association classes):
The following example shows that there is more to
allocating an employee to a project than making a simple
association link between the two classes: the role the
employee takes up on the project is a complex entity in its
own right and contains detail that does not belong in the
employee or project class. For example, an employee may
be working on several projects at the same time and have
different job titles and security levels on each.
45
Example:
46
Avoiding an association class
47
Qualifier:
• The attributes describing the association are called
qualifier.
48
Class Diagram
49
Example:
50
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.
51
52
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.
53