You are on page 1of 28

Advanced Software Engineering

Lecture-2

UML

1
UML Core Conventions
• Rectangles are classes or instances
• Ovals are functions or use cases
• Instances are denoted with an underlined names
• myWatch:SimpleWatch
• Joe:Firefighter
• Types are denoted with nonunderlined names
• SimpleWatch
• Firefighter
• Diagrams are graphs
• Nodes are entities
• Arcs are relationships between entities

2
UML: Use Case Diagrams
Used during requirements elicitation to
represent external behavior

Passenger
• Actors represent roles, that is, a type
of user of the system
• Use cases represent a sequence of
interaction for a type of functionality
• The use case model is the set of all
use cases. It is a complete description
of the functionality of the system and
its environment
PurchaseTicket

3
Actors
• An actor models an external entity
which communicates with the system:
• User
• External system
• Physical environment
Passenger • An actor has a unique name and an
optional description.
• Examples:
• Passenger: A person in the train
• GPS satellite: Provides the system with
GPS coordinates

4
Use Case
A use case represents a class of functionality
provided by the system as an event flow.

A use case consists of:


• Unique name
PurchaseTicket
• Participating actors
• Entry conditions
• Flow of events
• Exit conditions
• Special requirements

5
Use Case Example
Name: Purchase ticket Event flow:
1. Passenger selects the number of
Participating actor: Passenger zones to be traveled.
2. Distributor displays the amount
due.
Entry condition:
3. Passenger inserts money, of at least
• Passenger standing in front of ticket the amount due.
distributor.
4. Distributor returns change.
• Passenger has sufficient money to
purchase ticket. 5. Distributor issues ticket.

Exit condition: Anything missing?


• Passenger has ticket.
Exceptional cases!

6
The <<extend>> Relationship
• <<extend>> relationships represent
exceptional or seldom invoked cases.
Passenger • The exceptional event flows are factored
out of the main event flow for clarity.
• Use cases representing exceptional flows
can extend more than one use case.
PurchaseTicket • The direction of a <<extend>> relationship
is to the extended use case
<<extend>>

<<extend>>
<<extend>>

OutOfOrder <<extend>> TimeOut

Cancel NoChange
7
The <<include>> Relationship

• An <<include>> relationship
represents behavior that is
Passenger factored out of the use case.
• An <<include>> represents
PurchaseMultiCard
behavior that is factored out for
reuse, not because it is an
PurchaseSingleTicket exception.
<<include>> • The direction of a <<include>>
relationship is to the using use
<<include>>
case (unlike <<extend>>
relationships).

CollectMoney
<<extend>> <<extend>>

NoChange Cancel

8
Class Diagrams
TariffSchedule Trip
zone:Zone
Enumeration getZones() price:Price
* *
Price getPrice(Zone)

• Class diagrams represent the structure of the system.


• Class diagrams are used
• during requirements analysis to model problem domain concepts
• during system design to model subsystems and interfaces
• during object design to model classes.

9
Classes
TariffSchedule
Table zone2price
Enumeration getZones()
Name Price getPrice(Zone)

TariffSchedule Signature
zone2price Attributes
getZones()
getPrice()
Operations

• A class represent a concept.


• A class encapsulates state (attributes) and behavior (operations).
• Each attribute has a type.
• Each operation has a signature.
• The class name is the only mandatory information.
Instances

tariff_1974:TarifSchedule
zone2price = {
{‘1’, .20},
{‘2’, .40},
{‘3’, .60}}

• An instance represents a phenomenon.


• The name of an instance is underlined and can contain the class
of the instance.
• The attributes are represented with their values.
Actor vs. Instances
• What is the difference between an actor and a class and an
instance?
• Actor:
• An entity outside the system to be modeled, interacting with the
system (“Pilot”)
• Class:
• An abstraction modeling an entity in the problem domain, inside the
system to be modeled (“Cockpit”)
• Object:
• A specific instance of a class (“Joe, the inspector”).

12
Associations

TarifSchedule TripLeg

Enumeration getZones() price


* *
Price getPrice(Zone) zone

• Associations denote relationships between classes.


• The multiplicity of an association end denotes how many
objects the source object can legitimately reference.
1-to-1 and 1-to-Many Associations
Has-capital
Country City
1 1
name:String name:String

1-to-1 association

Polygon 1 * Point
x:Integer
y:Integer
draw()

1-to-many association

14
Aggregation
• An aggregation is a special case of association denoting a
“consists of” hierarchy.
• The aggregate is the parent class, the components are the
children class.

Exhaust System

1 0..2

Muffler Tailpipe
Composition
• A solid diamond denote composition, a strong form of
aggregation where components cannot exist without the
aggregate.

TicketMachine

3
ZoneButton
Generalization
Button

CancelButton ZoneButton

• Generalization relationships denote inheritance between classes.


• The children classes inherit the attributes and operations of the
parent class.
• Generalization simplifies the model by eliminating redundancy.

17
From Problem Statement to Code
Problem Statement
A stock exchange lists many companies. Each company is identified by a ticker symbol

Class Diagram
lists
StockExchange * * Company
tickerSymbol

Java Code

public class StockExchange {


public Vector m_Company = new Vector();
};
public class Company {
public int m_tickerSymbol;
public Vector m_StockExchange = new Vector();
};

18
UML Sequence Diagrams
• Used during requirements analysis
TicketMachine • To refine use case descriptions
Passenger • To find additional objects
selectZone() (“participating objects”)
• Used during system design
• to refine subsystem interfaces
• Classes are represented by columns
insertCoins()
• Messages are represented by arrows
• Activations are represented by narrow
rectangles
pickupChange()
• Lifelines are represented by dashed
lines

pickUpTicket()

19
UML Sequence Diagrams: Nested Messages

ZoneButton TarifSchedule Display


Passenger

selectZone()
lookupPrice(selection)

price

displayPrice(price)
Dataflow

…to be continued...

• The source of an arrow indicates the activation which sent the


message
• An activation is as long as all nested activations
Sequence Diagram Observations
• UML sequence diagram represent behavior in terms
of interactions.
• Complement the class diagrams which represent
structure.
• Useful to find participating objects.
• Time consuming to build but worth the investment.

21
Activity Diagrams
• An activity diagram shows flow control within a system

Handle Document Archive


Incident Incident Incident

• An activity diagram is a special case of a state chart


diagram in which states are activities (“functions”)
• Two types of states:
• Action state:
• Cannot be decomposed any further
• Happens “instantaneously” with respect to the level of abstraction used
in the model
• Activity state:
• Can be decomposed further
• The activity is modeled by another activity diagram

22
Activity Diagram: Modeling Decisions
[lowPriority]
Open Allocate
Incident Resources
[fire & highPriority]

[not fire & highPriority]


Notify
Fire Chief

Notify
Police Chief

23
Activity Diagrams: Modeling Concurrency
• Synchronization of multiple activities
• Splitting the flow of control into multiple threads

Splitting Synchronization

Allocate
Resources

Open Coordinate Archive


Incident Resources Incident

Document
Incident

24
Activity Diagrams: Swimlanes
• Actions may be grouped into swimlanes to denote
the object or subsystem that implements the actions.

Dispatcher
Allocate
Resources

Open Coordinate Archive


Incident Resources Incident

FieldOfficer
Document
Incident

25
Similarities Between Sequence and Activity Diagram:
•Both Sequence Diagram and Activity Diagram are UML diagrams.
•Both Sequence and Activity Diagrams are used to represent the control flow of
messages.

Difference between Sequence Diagram and Activity Diagram:


Sequence Diagram Activity Diagram

The Sequence diagram represents the UML, which is used to


visualize the sequence of calls in a system that is used to The Activity diagram represents the UML, which is used to
perform a specific functionality. model the workflow of a system.

The Sequence diagram shows the message flow from one The Activity diagram shows the message flow from one
object to another object. activity to another.

Sequence diagram is used for the purpose of dynamic Activity diagram is used for the purpose of functional
modelling. modelling.

Sequence diagram is used to describe the behavior of several


objects Activity diagrams is used to describe the general sequence
in a single use case of actions for several objects and use cases.

Sequence diagram is mainly used to represent the time order Activity diagram is used to represent the execution of the
of a process. process.

26
Group Assignment (30%)
Form a group 3 members, then identify scenario/problem and then
do the following:
1. Give appropriate title for the identified problem
2. Write background information and show the gap that the
proposed system will address.
3. Draw the following three UML Diagrams:
1. Use Case diagram
2. Class diagram
3. Sequence diagram

Deadline: Today + 21 days (June 05). You need to submit to your


representative on the 21st day before 4:00pm (afternoon). Then
representative should submit to me immediately from 4:00pm to
4:30pm (afternoon).
27
Summary
• UML provides a wide variety of notations for representing
many aspects of software development
• Powerful, but complex language
• Can be misused to generate unreadable models
• Can be misunderstood when using too many exotic features

• We concentrate only on a few notations:


• Functional model: use case diagram
• Object model: class diagram
• Dynamic model: sequence diagrams, statechart and activity diagrams

28

You might also like