CH 2 SE
CH 2 SE
(CoSc3061)
Sem. II – 2023
Department of Computer Science
Chapter -2
UML
An Overview of UML
What is modeling?
Extension : A use case can extend another use case by adding events , it allows
you to show optional system behavior
Cancel NoChange
The <<includes>> Relationship
<<includes>> relationship
represents behavior that is
Passenger factored out of the use case.
identifying commonalities in
different use cases
PurchaseMultiCard
<<includes>> behavior is
PurchaseSingleTicket factored out for reuse, not
<<includes>> because it is an exception.
<<includes>> The direction of a
<<includes>> relationship is to
the using use case (unlike
CollectMoney <<extends>> relationships).
<<extends>> <<extends>>
NoChange Cancel
Use Case Diagrams: Summary
Use case diagrams represent external behavior
Use case diagrams are useful as an index into the use cases
Use case descriptions provide meat of model, not the use
case diagrams.
All use cases need to be described for the model to be
useful.
Class Diagrams
Class diagrams describe the structure of
the system in terms of classes and objects
A class is a definition of objects that
share the same properties, relationships
and behavior.
An object is an instance of a class.
The properties of a object are called
attributes and the behavior is
expressed in operations.
Class Diagrams
Classes are the most important building block of any
object-oriented system
ClassName
attributes
operations
Classes are used to: -
capture the vocabulary of the system you are developing
represent software things, hardware things, and even things that are
purely conceptual
Well-structured classes have crisp/distinct
boundaries and form a part of a balanced distribution
of responsibilities across the system
Class Diagrams
TarifSchedule
Table zone2price
Enumeration getZones()
Name Price getPrice(Zone)
TarifSchedule
zone2price Attributes Signature
getZones()
getPrice()
Operations TarifSchedule
tarif_1974:TarifSchedule
zone2price = {
{‘1’, .20},
{‘2’, .40},
{‘3’, .60}}
name:String name:String
One-to-one association
Point
Polygon
* x: Integer
y: Integer
draw()
One-to-many association
Class Diagrams/ Relationships
Association/ multiplicity
Many-to-Many Associations
Lists
StockExchange * * Company
tickerSymbol
Class Diagrams/ Relationships
Generalization
A generalization is a relationship
between a general thing (superclass
or parent) and a more specific kind of
that thing (subclass or child)
Generalization means that objects of
the child may be used anywhere the parent
may appear, but not the reverse
the child is substitutable for the parent
27
Class Diagrams/ Relationships
Cont…
It supports polymorphism
An operation of the child that has
the same name/signature as an
operation in a parent overrides the
operation of the parent
28
Class Diagrams/ Relationships
Cont…
Graphically, a generalization is rendered as a
solid directed line with a large open
arrowhead, pointing to the parent
ParentClass
ChildClass
attributes
operations
29
Class Diagrams/ Relationships
How to Identify Generalization
To model inheritance relationship
Given a set of classes, look for responsibilities,
attributes and operations that are common to
two or more classes
Elevate those common responsibilities,
attributes and operations to a more general class.
If necessary, create a new class to which you can
assign these elements
Specify that the more-specific classes inherit
from the more-general class by placing a
generalization relationship that is drawn from
30 each specialized class to its more-general parent
Class Diagrams/ Relationships
Example: - The Rectangle, Circle and
Polygon classes inherits the attributes and
operations of the Shape class
Shape
origin
move()
resize()
display()
3
1
Class Diagrams/ Relationships
Aggregation
is a “whole-part” relationship within which one or
more smaller class are “part” of a larger “whole”
represents a “has-a” relationship, whereby an
object of the whole class has objects of the part
Company
whole 1
aggregation
part *
Department
32
UML represents an association class with a
regular class box and a dashed line that
connects the association class to the
association between the other two classes.
* 1..*
Company employer
Person
employee
association class
Job
description
dateHired
salary
3
3
Example: There’s a many-to-many relationship
between Author and Book, whereby an Author may
have written more than one book and a Book may
have more than one Author. The presence of the
BookAndAuthor association class allows us to pair
one Author with one Book: the role attribute allows
us to state whether the Author was the primary, or
supporting author, or editor or etc
* 1..* Book
Author
title: String
BookAndAuthor
role: String
3
4
To model structural relationship
(association): -
For each associations, specify a 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 there’s a many-to-many relationship
between two classes, use association class
(if possible)
3
5
A simple example
On-line Bookstore Review
a web application that can be accessed by the store’s
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 to
verify his/her ID and password
Each PASSWORD entered must be more than 8 characters and
consists of a combination of text and numbers
Each registered CUSTOMER, upon ACCOUNT verification, can
REVIEW one or more BOOKs based on its title
A REVIEW can either be a customer’s review and editor’s review
3
6
Things that are found in the
problem: -
Account
Password
Customer
Book
Review
can be divided into CustomerReview and
EditorialReview
3
7
Cont…
Each of these things can form
individual classes with
responsibilities (attributes and operation)
Account
Used to keep the customer’s ID and
password for verifying that the customer is
a registered customer
Also keeps additional information, i.e. e-
mail address
The password is of the type PASSWORD
3
8
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 customer’s name, ID, address etc
Book
Used to keep the relevant information on the
book that is crucial to customer’s review, i.e.
book title, author, rating
3
9
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 editor’s review
4
0
Translate the responsibilities for each class into attributes and
operations needed to perform those responsibilities (relevant to
the given problem)
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)
4 Book
1
Review
Attributes:NONE
Operations: NONE
CustomerReview
Attributes: NONE
Operations: NONE
4
2
The relationship between classes: -
Dependency
The operation verifyPassword in Account
class has as parameter a Password class
Therefore, Account depends on Password
Generalization
Review can be divided into customer’s review
and editor’s review
Therefore, CustomerReview and
EditorialReview is the subclass of Review
4
3
Association
A customer can open 1 account and an
account can be opened by 1 customer
A customer writes a review and a review
can be written by a customer
1 customer can write 1 or many reviews,
but 1 review can only come form 1
customer
A book can have many reviews but a
review is for one book
4
4
Modelling the classes and relationships: - EditorialReview
Book
title : String has
Review
1 *
Actors: Customer
Messages and Objects
1. The CUSTOMER clicks the Log-in button on the
Home Page.
2. The system displays the Log-in Page.
3. The CUSTOMER enters his/her user ID and
password. The CUSTOMER clicks the OK button.
5. The system validates the log-in information against the
ACCOUNT table in the database.
6. CUSTOMER is an authorised user; the system displays
the Personal Home Page to the CUSTOMER
:Customer :HomePage :LoginPage :Account
The Customer clicks
the Login button on clickLogin( )
the Home Page
58
Entity Objects
is an object that contains long-lived
information, such as that associated with
databases.
will be mapped to a table (part of the
database) in the design phase
It can also contain temporary objects, i.e.
contents of lists in windows, or search
results. entity object
59
Control Objects
is an object that embodies application logic
correspond with system actions (not actions
taken by actors)
are often used to handle things such as coordination
and sequencing
are also useful for calculations involving multiple
entity objects
will be mapped to codes during implementation
phase
used as a connecting tissue between boundary
objects and entitycontrol
objects .
object
60
Using the previous example (the log-in
use case of the Online Bookstore), we
can identify that
the HomePage and Log-in Page objects
are boundary objects,
whereas the Account object is an entity
object.
Therefore, taking this into account, we
can draw a new interaction diagram.
61
:Customer :HomePage :LoginPage :Account
63
On-line Bookstore is a web application that can be
accessed by the store’s registered customer,
whereby each customer can order books, review
one or more books sold in the book store, and sell
used books to other customers. Before performing
any one of these transactions, the customer must
first log-in into the system using their user id and
password kept in their account.
Problem: Draw the sequence diagram for the above
system
64
From previous discussions, we know that the
functional requirements for the Online
Bookstore can be seen from the use case
diagram (as shown in the next slide)
Each of the use cases in the use case diagram
must have its corresponding interaction diagram
We will use the scenarios in the ‘Main flow of
events’ for each use case to model the interaction
diagram
65
On-line Bookstore System
Register
<<extend>>
(CustID) Check out
Order books
<<include>>
Customer
<<include>>
Sell used Log-in
books
<<include>>
Review books
68
Register
verify info
clickProceed( )
display( )
display( )
choose destination
clickOK()
display()
confirm and clickOK ()
Use case: Sell used books
Main flow of events: -
1. The CUSTOMER clicks the Sell Used Books button on the Home
Page.
2. The system displays the sell used books web page.
3. The CUSTOMER enters the required information on the used
books that he/she wants to sell.
4. The CUSTOMER clicks the SEND button on the webpage.
5. The system displays a confirmation page listing the information
that the CUSTOMER has entered.
6. The CUSTOMER checks that the information displayed are
accurate. If yes, the CUSTOMER clicks the OK button on the web
page.
7. The system updates the USED BOOKS table in the database.
Objects:
HomePage, UsedBooksPage and ConfirmationPage: boundary objects
Customer and Used Books: entity objects
74
:Customer :HomePage :UsedBooksPage :ConfPage :Customer :UsedBook
clickUsedBooks( )
display( )
verify info
clickOK( )
add( )
add( )
75
Use case: Review
Main flow of events: -
1. The CUSTOMER enters the keyword to search for a book and
then clicks the SEARCH button on the Personal Web Page.
2. The system displays the matching books on the web Page.
3. The CUSTOMER checks for the desired book and clicks on the
chosen book icon.
4. The system displays the book’s detail in the Book Detail web
page.
5. The CUSTOMER clicks the REVIEW button on the web page.
6. The system displays the Review Book web page.
7. The CUSTOMER clicks on the desired star button and the
click the OK button on the web page.
8. The system calculates the overall rating of the book and
updates the Book table in the database.
9. The system displays the Book Detail web pages that have been
updated.
Objects?
Diagram?
76
State chart Diagrams
A state chart diagram is normally used to model
how the state of an object changes in its lifetime
State chart diagrams are good at describing how
the behavior of an object changes across several
use case executions
A state chart is a hierarchical model of a system
and introduces the concept of a composite state
(also called nested state).
The basic elements of the state chart diagram
are as follows:
Initial state- This is represented as a filled circle.
Final state- This is represented by a filled circle inside a larger circle
State- These are represented by rectangles with rounded corners.
Transition- A transition is shown as an arrow between two states.
State chart Diagrams
An example state chart for the order object of the Trade House Automation
software
Activity Diagrams
8
2
Cont…
All branches at some point are followed
by a merge to indicate the end of the
conditional behavior started by that
branch.
After the merge all of the parallel
activities must be combined by a join
before transitioning into the final activity
state.
8
3
Example to illustrate the activity of performing selling an
item to a customer.
8
4
Creating Activity Diagrams
885
5
Swimlanes
Included on activity diagrams to show
partitioning
Show which activities:
Occur on a browser
Occur on a server
Happen on a mainframe
Are done by external partners
Help to divide tasks among team members
886
6
Swimlane Boundaries
When an event crosses swimlane
boundaries, data must be transmitted.
A Web form is sent to a server.
Data are placed into middleware to
transmit it between a server and a
mainframe.
Data are transmitted to and from an
external partner.
87
Swimlanes
Activity diagrams are most often associated
with several classes.
The partition of activities among the
existing classes can be explicitly shown
using swimlanes.
88
Activity diagrams – an example with
swimlanes
89
Component Diagram
A component diagram describes the organization of the physical components
in a system.
Basic Component Diagram Symbols and Notations
Component
A component is a physical building block of
the system. It is represented as a rectangle
with tabs.
Interface
An interface describes a group of operations
used or created by components.
Dependencies
Draw dependencies among components
using dashed arrows.
Component Diagram
Component Diagram For Library Management System
Node
A node is a physical resource that
executes code components
Association
Association refers to a physical connection
between nodes, such as
Ethernet.