Chapter 2 &5-UML and Analysis (2&5)
Chapter 2 &5-UML and Analysis (2&5)
UML
— Chapter 2 —
Sisay N.
What is UML
◼ UML -Unified Modeling language and a blue print of
source code.
◼ It is a modeling language, not a methodology or process
◼ For visualizing, specifying, constructing and documenting the
artifacts of software systems.
◼ Visualizing - a picture is worth a thousand words; a
graphical notation articulates and unambiguously
communicates the overall view of the system (problem-
domain).
◼ Specifying - It provides the means to model precisely,
unambiguously and completely, the system in question.
What is UML
◼ Constructing - models built with UML have a
“design” dimension to it; these are language
independent and can be implemented in any
programming language.
◼ Documenting -every software project involves a lot of
documentation -from the inception phase to the
deliverables.
◼ It provides the notations for documenting some of
these artifacts such as Requirements, Design, Tests
etc.
Advantages of UML
◼ Most-Used and Flexible
◼ It is a highly recognized and understood platform for
software design.
◼ It is a standard notation among software developers.
◼ The Software Architecture Must Be Communicated
Effectively
◼ The software architecture is the blueprint of the system.
◼ It is the framework on which the efficiency of the system and
its processes depend.
◼ Effective if it is communicated properly to all those using
it and working on it.
◼ Can be used to model not just object-oriented software
engineering,
◼ But application structure and behavior, and business processes too.
UML in OOP concept
◼ UML can be described as the successor of object-
oriented (OO) analysis and design.
◼ An object contains both data and methods that control
the data and this data represents the state of the object.
◼ A class describes an object and they also form a
hierarchy to model the real-world system.
◼ Objects are the real-world entities that exist around us
◼ It represent an entity and the basic building block.
▪ Deployment view
▪ Specifications
▪ Adornments
▪ Common divisions
▪ Extensibility mechanisms
Building block of UML
◼ The building blocks of UML can be defined as Things,
Relationships and Diagrams
I. Things
◼ Things are the most important building blocks of UML. It
can be Structural, Behavioral, Grouping or Annotational.
Structural Things
◼ Structural things define the static part of the model and represent
the physical and conceptual elements.
◼ Following are the brief descriptions of the structural things.
◼ Class − Class represents a set of objects having similar
responsibilities.
◼ Interface − Interface defines a set of operations, which specify
the responsibility of a class.
◼ Collaboration −Collaboration defines an interaction between
elements.
◼ Use case −Use case represents a set of actions performed by a
system for a specific goal.
◼ Component −Component describes the physical part of a
system.
◼ Node − A node can be defined as a physical element that exists
at run time.
Behavioral Things
◼ The verbs of UML models; usually the dynamic parts
of the system in question.
◼ Interaction -some behaviour constituted by messages
exchanged among objects; the exchange of messages
is with a view to achieving some purpose.
◼ State machine -a behaviour that specifies the
sequence of “states” an object goes through, during
its lifetime.
◼ A “state” is a condition or situation during the
lifetime of an object during which it exhibits certain
characteristics and/or performs some function.
Grouping Things
◼ The organizational part of the UML model; provides a
higher level of abstraction (granularity).
◼ There is only one grouping thing available −
◼ Package -a general-purpose element that comprises
UML elements -structural, behavioral or even
grouping things.
◼ It used for gathering structural and behavioral
things.
◼ Used to group semantically related modeling
elements into a single cohesive unit.
Annotational Things
◼ Annotational things can be defined as a
mechanism to capture remarks, descriptions, and
comments of UML model elements.
◼ Note - It is the only one Annotational thing
available.
◼ A note is used to render comments, constraints, etc. of
an UML element.
◼ It is like a note, which may be written to the model to
capture some vital information.
◼ It is similar to the yellow sticky note. Here is an example
for annotation things in UML:
II. Relationship
◼ Relationship is another most important building
block of UML.
◼ It shows how the elements are associated with
each other and this association describes the
functionality of an application
◼ Articulates the meaning of the links between
things.
Dependency
◼ In UML, a dependency relationship is a relationship
in which one element, the client, uses or depends
on another element, the supplier.
◼ (arrow-head points to the independent thing)
◼ For example, the Person class might have a
hasRead method with a Book parameter that
returns true if the person has read the book
(perhaps by checking some database).
Association
◼ Association: a structural relationship that describes the
connection between two things
behavior
Flow of Events
• The most common thing for which you will apply use case
is to model the Functional behavior of an element ; A
system as a whole, a subsystem, or a class
– Focus on what that element does, not how it does Reasons for
applying use cases to elements
ClassName
attributes
operations
Name
Customer
Attribute
• An attribute is a named property of a class that describes a
range of values that instances of the property may hold
– represents some property of the thing you are modelling
that is shared by all objects of that class
– At any given moment, an object of a class will have specific
values for every one of it’s class attributes
• A class may have a number of attributes
• Attributes may be drawn showing only their names (a)
• Or, we can further specify an attribute by stating its type and
possibly a default initial value (b)
Operation
(a)
(b)
Cont…
dependent independent
• Dependencies are used in the context of classes to
show that one class uses another class as an
argument in the signature of an operation
– if the used class changes, the operation of the other
Course
• 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
•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
ParentClass
Circle
radius : Float
Association
• An association is a structural relationship that specifies
that objects of one thing are connected to objects of
another.
• we can navigate from an object of one class to an object
of the other class, and vice versa
• Types of association: -
➢ Unary association
➢where both ends of an association circle back to the same class
➢ Binary association
➢connects exactly two classes
➢ N-ary association
➢connects more than two classes
➢Graphically, an association is shown as a solid line connecting the
same or different classes
• There are 4 adornments that apply to associations: -
– Name
• An association can have a name to describe the nature of the
relationship
• A direction can also be given to the name by providing a
direction triangle that points in the direction intended (to read
t he name)
na m e
name direction
Works for
Person Company
association
– Role
• When a class participates in an association, it has a specific
role that it plays in the relationship
• A role is just the face that the class at the near end of the
association presents to the class at the other end of the
association
• An explicit name can be given to the role a class plays in an
association
association
Company
whole 1
aggregation
part *
Department
• Association Classes
➢ Sometimes in an association between two classes, the association itself
might have properties
➢ In the UML, you’ll 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 characteristics of its own
outside the classes it connects
• It comes in handy when you have many-to-many relationship that
you would like to break into a set of one-to-many relationships
– Warning: You cannot attach an association class to more than one
association
• UML represents an association class with a regular class box and a dashed line
*association between the other two
that connects the association class to the
classes.
1..
*
• 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
❖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)
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
– Keep generalization relationships generally balanced where the level of
inheritance should not be too deep
– Use associations only when there are structural relationships among
objects
A simple example
• Translate the responsibilities for each class into attributes and operations needed to perform those responsibilities
(relevant to the given problem)
• Attributes: NONE
• Operations: NONE
– CustomerReview
• Attributes: NONE
• Operations: assignRatings(rating : Int), computeAvgRating()
: double
– EditorialReview
• Attributes: NONE
• Operations: NONE
• 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
– 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
Object diagrams
•Object diagrams model the instances of things
contained in class diagrams
•An object diagram shows a set of objects and
their relationships at a point in time
•You use object diagrams to model the static
design view or static
process view of a system.
• involves modeling a snapshot of the system at a
moment in time and rendering a set of objects,
their state, and their relationships
• The UML notation for an object takes the same form as that for a class,
except for 3 differences:
– Within the top compartment of the class box, the name of the class
to which the object belongs to appears after a colon :
• The object may have a name that appears before the colon, or it may be
anonymous (no name before the colon)
– The contents of the top compartment are underlined for an object.
– Each attribute defined for the given class has a specific value for
each object that belong to that class.
Author
wrote
: Author : Book
wrote
Object diagram
: Book
wrote
published by
Object diagram
Sequences Diagram
• In every system, objects do not just sit idle; they interact with one
another by passing messages.
• In the UML, the dynamic aspects of a system is modelled using
interactions
– An interaction sets the stage for its behaviors by introducing
• all the objects that work together to carry out some action,
and
• the messages that are dispatched from object to object
Definition
• An interaction is a behaviors that comprises a set of
messages exchanged among a set of objects within a
context to accomplish a purpose.
• Interactions can be found wherever objects are linked
to one another, e.g.
– in the collaboration of objects that exist in the context
of a system and subsystem as a whole
– among objects in the implementation of an operation
– in the context of a class in order to visualize, specify,
construct and document the semantic of a class
116
Messages & Actions
• A message is a communication between two objects,
or within an object,that is designed to result in some
activity.
• This activity involves one or more actions, which are
executable statements that result in
– changes in the values of one or more attributes of
an object, or the return of some value(s) to the
object that sent the message, or both
• There are 5 kinds of actions that the UML explicitly
supports: -
– Call and Return; Create and Destroy; Send
117
• Call action
– A call action invokes an operation on an object
– It is synchronous, meaning that
• the sender assumes that the receiver is ready to accept the message,
• and the sender waits for a response from the receiver before proceeding
– The UML represents a call action as an arrow from the calling object to the
receiving object
A lifeline
action name
A call action
from an object
to itself
118
• Return action
– A return action is the return of a value to the caller, in response
to a call action
– The UML represents a return action as a dashed arrow from the
object returning the value to the object receiving the value
return value
119
Example :- Call and Return
action
: Customer : CustomerReview
assignRating()
computeAvgRating()
average rating
120
Example for Call and Return Actions
<<create>> <<create>>
: Class
122
• Destroy action
– A destroy action destroys an object
• It tells an object to destroy itself
– An object can perform a destroy action on another object, or on itself
– In the UML, a destroy action is represented as an arrow with the
stereotype <<destroy>> from the object that invokes the action to the
destroyed object. A large X is also added at the end of the destroy arrow to
denote that the object’s lifeline has been terminated
<<destroy>>
X
123
Example for creation and Destroy
•Create Action:
•This action is responsible for creating a new instance of a class. It
initializes the object and assigns values to its attributes if needed.
•Example: In a bank system, creating a new Account object when a
customer registers.
•Destroy Action:
•This action removes an existing object from the system, often freeing up
memory or closing processes.
•Example: Deleting a Session object when a user logs out.
• Send action
– A send action sends a signal to an object
– A signal is an asynchronous communication between objects
• One object “throws” a signal to another object that “catches” the signal
• The sender of the signal does not expect a response from the receiver (unlike the
sender of a call action)
• Exceptions are the most common type of signals
– In the UML, a send action is represented as an arrow with a half
arrowhead at the lifeline of the receiving object
action name
Send Action:
•It’s used to send a signal or message from one object to another without waiting for a response. This is often seen in asynchronous
communication.
•Example: An Order object sends a confirmation email to a Customer object.
Modelling an interaction
126
Cont
…
• In the UML, an interaction diagram is used to model the dynamic aspect
of a system.
• These dynamic aspect may involve : -
– the interaction of any kind of instance in any view of a system’s
architecture, including instances of a class, interface, components
and nodes.
– a system as a whole, a subsystem, an operation or a class
•An interaction diagram can be used in two ways: -
–To model flows of control by time ordering
•emphasizes the passing of messages as they unfold over time
•Sequence Diagram is used to model this
–To model flows of control by organization
•emphasizes the structural relationships among the instances in the
interaction, along which messages may be passed
•Collaboration Diagram is used to model this
Sequence diagram…
128
• A sequence diagram has four key elements:
– Objects appear along the top margin
– Each object has a lifeline, which is a dashed line that represent the life and
perhaps death of the object
• Most objects will be in existence for the duration of the interaction
• Objects may also be created during the interaction, or destroyed
– A focus of control, which is a tall thin rectangle that sits on top of an object’s
lifeline
• It shows the period of time during which an object is performing an action,
either directly or through subordinate procedure
• The bottom part of a focus of control can be marked by a return message
– Messages show the actions that objects perform on each other and on themselves
138
objects
C : Client p : ODBCProxy
<<create>>
: Transaction
setActions(a, d, o)
setValues(d, 3, 4)
<<destroy>> lifeline
X
focus of control
130
• You built sequence diagrams or collaboration diagrams from the use-
case and class diagrams that were built before.
– Each use cases in a use-case diagram has its corresponding
sequence or collaboration diagram
– You model the diagrams from the main flow of events, or the
alternate flow of events, or the scenarios, of each use case
– Every object that you have identified in the sequence or
collaboration diagram, MUST have its corresponding class in the
class diagram
131
• Example: - Modelling a sequence diagram for the log-in use case from the on-line
Bookstore Case Study.
– The main-flow of events that are involved is: -
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.
4. The system validates the log-in information against the ACCOUNT
table in the database.
5. CUSTOMER is an authorised user; the system displays the Personal
Home Page to the CUSTOMER
132
– 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
133
:Customer :HomePage :Account
:LoginPage
boundary object
135
• 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 transient objects, i.e. contents of lists in windows, or search
results.
entity object
148
• 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 entity objects.
control object
137
• 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.
138
:LoginPag
:Customer :HomePage e :Account
142
• Case Study: Order Books
– Main Flow of events: -
1. The CUSTOMER enters the keyword for a book and clicks the
SEARCH button on the personal Home Page.
2. The system displays the matching books on the web Page.
3. The CUSTOMER chooses the desired book and clicks the ADD TO
SHOPPING CART button on the web page.
4. The system adds the book into the CUSTOMER’s Order table in the
database.
– Objects:
• Customer: actor
• Home Page: boundary object
• Book and Order: entity object
160
161
• 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:
• Home Page, Used Books Page and Confirmation Page: boundary objects
• Customer and Used Books: entity objects
162
• 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?
Activity Diagram
•Activity diagrams describe the workflow behavior of a system.
•They are typically used for business process modeling, for modeling the logic
captured by a single use case or usage scenario, or for modeling the detailed logic
of a business rule.
•UML activity diagrams could potentially model the internal logic of a complex
operation.
•In many ways UML activity diagrams are the object-oriented equivalent of flow
charts.
•Activity diagrams do not give detail about how objects behave or how objects
collaborate.
•Diagrams are read from top to bottom and have branches and forks to describe
conditions and parallel activities.
•A fork is used when multiple activities are occurring at the same time.
•Activity diagrams show the sequence of activities in a process, including
sequential and parallel activities.
•Symbols are used for activities, decisions and so on.
•Arrows represent events that connect the activities.
Cont…
THANKS
quiz
◼ Amazon is an online shopping platform where
customers can browse products, add items to
their cart, and place orders. Once an order is
placed, Amazon processes the payment and ships
the product to the customer’s address. Customers
can also track their orders and leave reviews for
purchased items.
1. Identify Use Cases:
List at least five major use cases involved in the
Amazon online shopping process.
2. Identify Classes:
Identify and list at least four potential classes
involved in this system.
quiz
◼ Questions:
1. Identify Use Cases:
List at least five major use cases involved in the Amazon online shopping
process.
2. Identify Classes:
Identify and list at least four potential classes involved in this system.
3. Identify Objects:
From the classes identified above, provide two possible objects for each class.
4. Draw a Use Case Diagram:
Using the identified use cases, draw a use case diagram showing the
interactions between actors and the use cases.
5. Draw a Class Diagram:
Using the identified classes, draw a class diagram. Include attributes,
methods, and relationships between the classes (like association, aggregation,
or inheritance).
6. Draw an Object Diagram:
Choose any two classes and draw an object diagram that shows real-world
instances (objects) and their relationships.
Some solution
◼ . Identify Use Cases:
Here are at least five major use cases for the Amazon online shopping
platform:
• Browse Products: Customers search and view available products.
• Add to Cart: Customers select products and add them to their virtual
shopping cart.
• Place Order: Customers confirm their cart and initiate the purchase
process.
• Process Payment: Amazon handles customer payment through
different methods (credit card, PayPal, etc.).
• Ship Product: Amazon ships the purchased product to the
customer’s provided address.
• Track Order: Customers monitor the status and delivery progress of
their orders.
• Leave Review: Customers provide feedback and rate purchased
products.
solution
Identify Classes:
Here are at least four potential classes involved in the system:
•Customer: Represents the user who buys products.
•Attributes: customer_id, name, email, address
•Methods: register(), login(), placeOrder(), trackOrder(), leaveReview()
•Product: Represents items available for purchase.
•Attributes: product_id, name, description, price, stock_quantity
•Methods: getDetails(), updateStock(), addReview()
•Order: Represents a customer’s purchase transaction.
•Attributes: order_id, order_date, status, total_amount
•Methods: createOrder(), cancelOrder(), trackOrder()
•Payment: Handles the payment process for orders.
•Attributes: payment_id, payment_method, amount, payment_status
•Methods: processPayment(), confirmPayment()
Solution