Lect8a UML

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 81

UML

Unified Modelling
Language
Dr. Santosh Kumar Swain
Professor
School Of Computer Engineering
KIIT , Bhubaneswar.

10/22/2024 1
Different Object Modeling
Techniques in UML

OMT

UML
Booch’s
OOSE
Methodology
Background

• 1996 – Release of UML 0.9 by by Grady Booch,


Jim Rumbaugh of Rational Software Corporation,
Ivar Jacobson of Objectory company.
• 1996 – Release of UML 1.0 by Digital
Equipment, HP, Ilogix, IntelliCorp, IBM, ICON,
MCI, Microsoft, Oracle, Rational, TI and Unisys.
• 1997 – Release of UML 1.1 by IBM, ObjecTime,
Platinum, Ptech, Taskon, Reich and Softeam
• 2001 – Work on UML 2.0 specifications.
KIIT SCHOOL of COMPUTER ENGINEERING 3
UML Lineology
Based Principally on:
 OMT [Rumbaugh 1991]
 Booch’s methodology[Booch 1991]
 OOSE [Jacobson 1992]
 Odell’s methodology[Odell 1992]
 Shlaer and Mellor [Shlaer 1992]
UML Diagrams
Behavioural View
Structural View - Sequence Diagram
- Class Diagram - Collaboration Diagram
- Object Diagram - State-chart Diagram
- Activity Diagram
User’s View
- Use Case
Diagram

Implementation View Environmental View


- Component Diagram - Deployment Diagram

Diagrams and views in UML


Relationships
UML have 4 kinds of relationships:
• Association – Two classes are associated if one class has
to know about the other.
o Aggregation – An association in which one class belongs to
a collection in the other.
o Composition
• Generalization – An inheritance link indicating one class is
a base class of the other.
• Dependency – A labeled dependency between classes
(such as friend classes, instantiation)
• Realization --
KIIT SCHOOL of COMPUTER ENGINEERING 6
KIIT SCHOOL of COMPUTER ENGINEERING 7
System boundary:
indicates the scope of your system.

Use case diagram Anything within the box represents


functionality that is in scope and
anything outside the box is not
System
boundary

• overview the usage requirements


Actor • presentations project stakeholders
• "the meat" of the actual requirements
Actor:

An actor is a person, organization, or


external system that plays a role in one
or more interactions with your system
Use case
Use case:
A use case describes a sequence of
actions that provide something of
measurable value to an actor and is
Online C2C shopping
drawn as a horizontal ellipse
8
Use Case Diagrams

• Describes what a system does from the standpoint of an


external observer.
• Emphasis on what a system does rather then how.
• Scenario – an example of what happens when someone
interacts with the system.
• Actor – A user or another system that interacts with the
modeled system.
• A use case diagram describes the relationships between
actors and scenarios.
• Provides system requirements from the user’s point of
view.
KIIT SCHOOL of COMPUTER ENGINEERING 9
Use Case Diagrams

UML defines 3 kinds of associations:


• Association – defines a relationship between
an actor and a use case.
• Extend - defines that instances of a use case
may be augmented with some additional
behavior defined in an extending use case.
• Uses - defines that a use case uses a behavior
defined in another use case.

KIIT SCHOOL of COMPUTER ENGINEERING 10


Use Case Relation
• <<include>> used when one use case will
invoke another use case.
• <<extends>> used when one use case may
invoke another use case.

KIIT SCHOOL of COMPUTER ENGINEERING 11


Representation of
Use Cases
• Represented by use case diagram
• A use case is represented by an ellipse
• System boundary is represented by a rectangle
• Users are represented by stick person icons
(actor)
• Communication relationship between actor and
use case by a line
• External system by a stereotype
Use Case Diagram Example1

Play Move

Tic-tac-toe game
Player

Use case model


Use Case Example2

KIIT SCHOOL of COMPUTER ENGINEERING 14


Use Case Model
• Consists of set of “use cases”
• An important analysis and design artifact
• The central model:
– Other models must confirm to this model
– Not really an object-oriented model
– Represents a functional or process model
Use Cases
• Different ways in which a system can be used by
the users
• Corresponds to the high-level requirements
• Represents transaction between the user and
the system
• Defines external behaviour without revealing
internal structure of system
• Set of related scenarios tied together by a
common goal.
Use Cases
Cont…
• Normally, use cases are independent of each
other
• Implicit dependencies may exist
• Example: In Library Automation System,
renew-book and reserve-book are independent
use cases.
– But in actual implementation of renew-book--- A
check is made to see if any book has been reserved
using reserve-book.
Example Use Cases
–Library information system
• issue-book
• query-book
• return-book
• create-member
• add-book, etc.
Factoring Use Cases
• Two main reasons for factoring:
– Complex use cases need to be factored into
simpler use cases
– To represent common behavior across
different use cases
• Three ways of factoring:
– Association/Generalization
– Includes
– Extends
Factoring Use Cases Using
Generalization

Pay membership fee

Pay through credit card Pay through library pay card


Factoring Use Cases Using
Includes
<<include>> Common
Base use case
use case

Base use case 2 Base use case 1

<<include>>
<<include>>
<<include>> <<include>>

Common use case Common use case Common use case


Example of Factoring Use Cases
Using Includes

Issue Book Renew Book

<<include>>
<<include>>

Check Reservation
Factoring Use Cases Using
Extends

Base <<extends>> Common


use case use case
Factoring Use Cases Using
Extends

Order <<extends>> Show


Item Catalog
Class Diagram

Name Class diagrams show the classes of the


system, their interrelationships (including
inheritance, aggregation, and association),
and the operations and attributes of the
classes.

• Associations
• Aggregation
Relations • Generalization
Attributes

Operations

25
Class Diagram
• Displays objects structure, contents and
relationships.
• Class diagrams are static – display what
interacts but not what happens when
interaction occurs.

KIIT SCHOOL of COMPUTER ENGINEERING 26


Class Diagram
• Classes are represented by a rectangle divided to three
parts: class name, attributes and operations.
• Attributes are written as:
visibility name [multiplicity] : type-expression = initial-value
• Operations are written as:
visibility name (parameter-list) : return type-expression
• Visibility is written as:
+ public
# protected
- private
KIIT SCHOOL of COMPUTER ENGINEERING 27
Class Diagrams
Class Diagrams describe the static structure of a system, or how it
is structured rather than how it behaves. These diagrams
contain the following elements.
• Classes, which represent entities with common
characteristics or features. These features include attributes,
operations and associations.
• Associations, which represent relationships that relate two
or more other classes where the relationships have common
characteristics or features. These attributes and operations.

KIIT SCHOOL of COMPUTER ENGINEERING 28


Class Diagram
• Describes static structure of a system
• Main constituents are classes and their
relationships:
– Generalization
– Aggregation
– Association
– dependencies
Connected as a graph to each other and to their
contents
Class Diagram
• Entities with common features, i.e. attributes
and operations.
• Classes are represented as solid outline
rectangle with compartments.
• Compartments for name, attributes, and
operations.
• Attribute and operation compartments are
optional depending on the purpose of a
diagram.
Visibility

KIIT SCHOOL of COMPUTER ENGINEERING 31


Class Diagram

KIIT SCHOOL of COMPUTER ENGINEERING 32


Object Diagram
• Shows snapshot of detailed state of the
system at a point of time.
• Notation is same a class diagram.
• Class diagrams can contain objects
So a class diagram with objects and no classes is
an object diagram.

KIIT SCHOOL of COMPUTER ENGINEERING 33


Object Diagrams
Object Diagrams describe the static structure of a system at a
particular time. Whereas a class model describes all
possible situations, an object model describes a particular
situation. Object diagrams contain the following elements:
• Objects, which represent particular entities. These are
instances of classes.
• Links, which represent particular relationships between
objects. These are instances of associations.

KIIT SCHOOL of COMPUTER ENGINEERING 34


Object Diagram
LibraryMember

Mritunjay LibraryMember LibraryMember


B10028
C-108, Laksmikant Hall Mritunjay
1119 B10028
Mrituj@cse C-108, Laksmikant Hall
25-02-04 1119
25-03-06 Mrituj@cse
NIL 25-02-04
25-03-06
IssueBook( ); NIL
findPendingBooks( );
findOverdueBooks( );
returnBook( );
findMembershipDetails( );

Different representations of the LibraryMember object


Interaction Diagram
• Models how groups of objects
collaborate to realize some behaviour
• Typically each interaction diagram
realizes behaviour of a single use case
Interaction Diagram
• Two kinds:
–Sequence and Collaboration diagrams.
• Two diagrams are equivalent
– Portray different perspectives
• These diagrams play a very important role
in the design process.
Sequence Diagram
• Shows interaction among objects as a two-
dimensional chart
• Objects are shown as boxes at top
• If object created during execution then shown
at appropriate place
• Objects existence are shown as dashed lines
(lifeline)
• Objects activeness, shown as a rectangle on
lifeline
Sequence Diagram

Object: Class
• A sequence diagram is
• An interaction diagram that
details how operations are
carried out.
• What messages are sent and
when.
• Sequence diagrams are
organized according to time

Message
Operations

Lifeline

39
Sequence Diagram Cont…
• Messages are shown as arrows.
• Each message labelled with corresponding
message name.
• Each message can be labelled with some
control information.
• Two types of control information:
– condition ([])
– iteration (*)
Elements of a Sequence Diagram
: Customer : Order : Payment : Product : Supplier

place an order

object process

validate

control lifetime
if ( payment ok )
if ( not in stock )
deliver
back order

get address

mail to address

message
Example
Cont…

: Customer : Order : Payment : Product : Supplier

place an order

process

validate

Sequence of message sending


if ( payment ok )
if ( not in stock )
deliver
back order

get address

mail to address
An Example of
A Sequence Diagram
:Library
:Library
:Library Book :Library
Book :Book
Boundary Renewal Member
Register
Controller

renewBook find MemberBorrowing


displayBorrowing
selectBooks bookSelected
* find
[reserved]
[reserved] apology
update
apology

confir
m

confirm
updateMemberBorrowing

Sequence Diagram for the renew book use case


Collaboration Diagram
• Shows both structural and behavioural aspects
• Objects are collaborator, shown as boxes
• Messages between objects shown as a solid
line
• A message is shown as a labelled arrow placed
near the link
• Messages are prefixed with sequence numbers
to show relative sequencing
An Example of
A Collaboration Diagram
6: * find
:Library
Book :Book
[reserved] Register
9: update
8: apology 5: book 10:
Selected confirm

1: [reserved]
:Library
renewBook
:Library Book 7: apology
Boundary 3: display Renewal
Borrowing Controller

4: selectBooks
2: findMemberBorrowing

12: confirm
:Library
Member

updateMemberBorrowing

Collaboration Diagram for the renew book use case


Activities Diagram

Start
Fork
Activity diagrams describe the workflow
behaviour of a system

Branch

Merge Joint

End
46
Activity Diagram
• Not present in earlier modelling techniques:
– Possibly based on event diagram of Odell [1992]
• Represents processing activity, may not
correspond to methods
• Activity is a state with an internal action and
one/many outgoing transitions
• Somewhat related to flowcharts
Activity Diagram vs Flow Chart
• Can represent parallel activity and
synchronization aspects
• Swim lanes can be used to group
activities based on who is performing them
• Example: academic department vs. hostel
Activity Diagram
• Normally employed in business process
modelling.
• Carried out during requirements
analysis and specification stage.
• Can be used to develop interaction
diagrams.
An Example of
An Activity Diagram
Academic Section
Accounts Section Hostel Office Hospital Department
check
student
records
receive
fees

allot create
hostel hospital
record
register
receive
in
fees
course
conduct
allot medical
room examination

issue
identity card
Activity diagram for student admission procedure at IIT
Activity Diagram: Example 2
Finance Order Stock
Receive Processing Manager
Order Receive
Supply
*[for each line
item on order] Choose
Check Outstanding
Authorize [failed] Line Item Order Items
Payment
* [for each chosen
[in stock] order item]
Cancel
Order Assign
Assign to
[succeeded] Order Goods to
Order

[need to reorder]
Reorder
Item

[stock assigned to all [all outstanding


line items and payment order items filled]
Dispatch
authorized] Order
State Chart Diagram
• Based on the work of David
Harel [1990]
• Model how the state of an object
changes in its lifetime
• Based on finite state machine (FSM)
formalism
State Chart Diagram
Cont…
• State chart avoids the problem of
state explosion of FSM.
• Hierarchical model of a system:
–Represents composite nested
states.
State Machine Diagram

A State Machine diagram


shows the possible states of
the object and the transitions
that cause a change in state.

What is different
?
between activities
and Statemachine
diagram

54
State Chart Diagram
Cont…

• Elements of state chart diagram


• Initial State: A filled circle
• Final State: A filled circle inside a larger circle
• State: Rectangle with rounded corners
• Transitions: Arrow between states, also
boolean logic condition (guard)
An Example of A State Chart
Diagram
order received
Unprocessed
Order
[reject] checked [accept] checked

Rejected Accepted
Order Order
[some items available]
[some items not processed / deliver
available] processed

[all items
Pending available] Fulfilled
Order newsupply Order

Example: State chart diagram for an order object


Package Diagrams
• A package is a grouping of several
Order Capture Mailing List
classes: UI
AWT
UI
– Java packages are a good example
• Package diagrams show module
dependencies.
• Useful for large projects with Order Capture Mailing List
Application Application
multiple binary files
Dependency
Common
{global}
Oracle Quantity
Interface Domain
Money
DateRange

Database Orders Customers


Sybase
Interface
Interface
{abstract}
Component Diagram
• Captures the physical structure of the
implementation (code components)

dependency

Components:
• Executables
• Library
• Table
• File
• Document
Component Diagram
• Captures the physical structure of the
implementation
• Built as part of architectural specification
• Purpose
– Organize source code
– Construct an executable release
– Specify a physical database
• Developed by architects and programmers
Deployment Diagram
• Captures the topology of a system’s
hardware

A piece of
hardware
Are All Views Required for Developing A
Typical System?
NO
For a simple system:
 Use case diagram, class diagram and one of the
interaction diagrams only.
State chart diagram:
 when class has significant states.
 When states are only one or two, state chart model
becomes trivial
Deployment diagram:
 In case several hardware components used to
develop the system.
A Design Process
– Developed from various methodologies.
• However, UML has been designed to be usable
with any design methodology.
– From requirements specification, initial
model is developed (OOA)
• Analysis model is iteratively refined into a design
model
– Design model is implemented using OO
concepts
OOAD
Iterative and Incremental

OOA OOD/OOP

Domain
Specification Model Construction of
Definition of Program
the problem Use the solution
case
model
Unified Development Process
Cont…
OOA OOD

User interface
Use case Interaction
Issues or GUI
prototype diagram diagram

Start

SRS document Domain model Class diagram Code

Glossary
Example 1: Tic-Tac-Toe Computer Game

• A human player and the computer make


alternate moves on a 3 3 square.
• A move consists of marking a previously
unmarked square.
• The user inputs a number between 1 and 9 to
mark a square
• Whoever is first to place three consecutive
marks along a straight line (i.e., along a row,
column, or diagonal) on the square wins.
Example 1: Tic-Tac-Toe Computer Game

• As soon as either of the human player or the


computer wins,
– A message announcing the winner should be
displayed.
• If neither player manages to get three
consecutive marks along a straight line,
– And all the squares on the board are filled up,
– Then the game is drawn.
• The computer always tries to win a game.
Example 1: Use Case Model

Play Move

Player Tic-tac-toe game


Example 1: Initial and Refined Domain
Model

Board

Initial domain model

PlayMoveBoundar PlayMoveControll
Board
y er

Refined domain model


Example 1: Sequence Diagram

:playMove :playMove
Boundary Controller
:board

acceptMove checkMoveValidity
move
[invalidMove] [invalidMove]
announceInvalidMove
announceInvalidMove
checkWinner
[game over]
[game over] announceResult
announceResult
playMove
checkWinner

[game over] [game over]


announceResult announceResult

displayBoardPositions getBoardPositions

[game not over]


promptNextMove

Sequence Diagram for the play move use case


Example 1: Class Diagram

Board PlayMoveBoundary

int position[9]

checkMove Validity announceInvalidMove


checkResult announceResult
playMove displayBoard

Controller

announceInvalidMove
announceResult
Example 2: Supermarket Prize Scheme

• Supermarket needs to develop software to


encourage regular customers.
• Customer needs to supply his:
– Residence address, telephone number, and the
driving licence number.
• Each customer who registers is:
– Assigned a unique customer number (CN) by the
computer.
Example 2: Supermarket Prize Scheme

• A customer can present his CN to the staff


when he makes any purchase.
• The value of his purchase is credited
against his CN.
• At the end of each year:
– The supermarket awards surprise gifts to ten
customers who make highest purchase.
Example 2: Supermarket Prize Scheme

• Also, it awards a 22 carat gold coin to


every customer:
– Whose purchases exceed Rs. 10,000.
• The entries against the CN are reset:
– On the last day of every year after the prize
winner’s lists are generated.
Example 2: Use Case Model

register
Customer customer Clerk

register
sales

Sales Clerk
select
winners

Supermarket
Prize scheme
Manager
Example 2: Initial Domain Model

CustomerRegiste
SalesHistory
r
1 1

* *
SalesRecords CustomerRecord

Initial domain model


Example 2: Refined Domain Model

CustomerRegiste
SalesHistory
r
1 1

* *
SalesRecords CustomerRecord

RegisterCustomerBound RegisterCustomerContr
ary oller

RegisterSalesBoundary RegisterSalesController

SelectWinnersController
SelectWinnersBoundary
s

Refined domain model


Example 2: Sequence Diagram for the Select
Winners Use Case
:SelectWinner :SelectWinner :Sales :Sales :Customer :Customer
Boundary Controller History Record Register Record

Select
SelectWinners
Winners
SelectWinners
*computeSales

*browse

[for each winner]


find WinnerDetails [for each winner]
announces
browse

Sequence Diagram for the select winners use case


Example 2: Sequence Diagram for the
Register Customer Use Case
:RegisterCustomer :RegisterCustomer :Customer :Customer
Boundary Controller Register Record

register
register
checkDuplicate
*match

[duplicate]

showError
generateCIN

create
register :Customer
Record
displayCIN

Sequence Diagram for the register customer use case


Example 2: Sequence Diagram for the
Register Sales Use Case

:Register :Register
:Sales
Sales Sales
History
Boundary Controller

RegisterSales registerSales
registerSales

create :Sales
Record

confirm
confirm

Sequence Diagram for the register sales use case


Example 2: Sequence Diagram for the
Register Sales Use Case

:Register
:Sales
Sales
History
Boundary

registerSales
RegisterSales

create :Sales
Record

confirm

Refined Sequence Diagram for the register sales use case


Example 2: Class Diagram

SalesHistory CustomerRegister

selectWinners findWinnerDetails
registerSales register

1 1

* *
SalesRecords CustomerRecord

salesDetails name
address
computerSales browse
browse checkDuplicate
create create

You might also like