Modelling with UML - PowerPoint PPT Presentation

1 / 59
About This Presentation
Title:

Modelling with UML

Description:

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: ... IBM Webcast Recorded Event Feb15 Intro.itm in http://developer.raindance.com/iccdoc ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 60
Provided by: bernd191
Category:

less

Transcript and Presenter's Notes

Title: Modelling with UML


1
Modelling with UML
CS223 Lecture 4 (see BD Ch. 2) Ananda
Amatya Notice Surgery Sessions (Weeks 6-10)
Mon 2 - 4 in C1.01 Fri 9 - 11 in C1.04 Please
attend any one session convenient to you
2
Overview modelling with UML
  • What is modelling?
  • What is UML?
  • Use case diagrams
  • Class diagrams
  • Sequence diagrams (Collaboration diagrams)
  • Activity diagrams
  • StateChart diagrams

3
What is modelling?
  • Modelling
  • building an abstraction of reality.
  • Abstractions
  • simplifications
  • ignore irrelevant details
  • focus on matters of concern.
  • What is relevant and what is irrelevant?
  • depends on the purpose of the model.

4
Example street map that models access roads
5
Why model software?
  • More sophisticated software means more
    complexity
  • Windows XP gt 40 million lines of code
  • Several coders must be involved.
  • One developers code must be understood by
    another developer.
  • Complex systems must be simplified
  • Modelling is a way of achieving this.

6
Systems, Models and Views
  • System an organised set of communicating parts.
  • Model an abstraction describing a subset of a
    system.
  • View a selected aspect of a model.
  • Notation a set of graphical or textual rules for
    depicting views.
  • Views and models of a single system may overlap
    each other.
  • Examples
  • System Aircraft
  • Models Flight simulator, scale model
  • Views All blueprints, electrical wiring, fuel
    system

7
Systems, Models and Views
Blueprints
Flightsimulator
Aircraft
Fuel System
Scale Model
Electrical Wiring
8
Models, Views and Systems (UML)


System
Model
View
Depicted by
Described by
Airplane System
Scale Model Model
Flight Simulator Model
Blueprints View
Fuel System View
Electrical Wiring View
9
Concepts and Phenomena
  • Phenomenon
  • An object in the world of a domain as you
    perceive it.
  • Examples this lecture, that wall clock
  • Concept
  • An abstraction that describes phenomena with
    common properties.
  • Examples Lecture, Wall clock
  • Concept is a 3-tuple
  • Name (to distinguish one concept from another)
  • Purpose (to determine if a phenomenon belongs to
    a concept)
  • Members (the set of phenomena that belong to the
    concept - instances)

10
Concepts and Phenomena (contd.)
  • Abstraction
  • Classification of phenomena into concepts
  • Modelling
  • Development of abstractions to answer specific
    questions about a set of phenomena while ignoring
    irrelevant details.

11
Concepts in software Type and Instance
  • Type
  • An abstraction in the context of programming
    languages
  • Name int,
  • Purpose integral number,
  • Members 0, -1, 1, 2, -2, . . .
  • Instance
  • Member of a specific type
  • The type of a variable represents all of its
    possible instances
  • The following relationships (ltgt) are similar
  • type ltgt instance
  • concept ltgt phenomenon

12
Abstract Data Types Classes
  • Abstract data type
  • Special type whose implementation is hidden from
    the rest of the system.
  • Class
  • An abstraction in the context of object-oriented
    languages
  • Like an abstract data type, a class encapsulates
    both state (variables) and behaviour (methods)
  • Example Class Watch
  • Unlike abstract data types, classes can be
    defined in terms of other classes using
    inheritance

13
Application and Solution Domain
  • Application Domain (Requirements Analysis)
  • The environment in which the system is operating
  • Solution Domain (System Design, Object Design)
  • The available technologies to build the system

14
Object-oriented modelling
Application Domain
Solution Domain
UML Package
TrafficControl
SummaryDisplay
MapDisplay
TrafficController
FlightPlanDatabase
Aircraft
Airport
TrafficControl
FlightPlan
System Model
Application Domain Model
15
What is UML?
  • UML (Unified modelling Language)
  • A standard for modelling object-oriented
    software.
  • Resulted from the convergence of notations from
  • OMT (James Rumbaugh)
  • OOSE (Ivar Jacobson)
  • Booch (Grady Booch)
  • Reference OMG (Object Management Group)
  • Supported by several CASE tools
  • Rational ROSE (IBM)
  • Poseidon (ArgoUML)
  • TogetherJ (Borland)
  • Rhapsody (ILogix)
  • Eclipse (IBM)

16
UML First Pass
  • You can model 80 of most problems by using about
    20 UML
  • We teach you those 20

17
UML First Pass
  • Use case Diagrams
  • describe a systems functional behaviour as seen
    by its user.
  • Class diagrams
  • describe a systems static structure Classes,
    Associations
  • Sequence diagrams
  • describe a systems dynamic behaviour actors,
    objects, messages
  • Statechart diagrams
  • describe the dynamic behaviour of individual
    objects of the system states, events,
    transitions
  • Activity Diagrams
  • model a systems dynamic behaviour activities,
    workflows (flowcharts)

18
UML first pass Use case diagrams
Use case
Package
Actor
Use case diagrams represent the systems
functionality from users point of view
19
UML first pass Class diagrams
Association
Class
Multiplicity
Watch
1
2
PushButton
state
push()release()
Attribute
Operations
Class diagrams represent the structure of the
system
20
UML first pass Sequence diagram
Actor
Object
Message
Activation
Lifeline
Sequence diagrams represent the behaviour as
interactions
21
UML first pass Statechart (diagrams) for objects
with interesting dynamic behaviour
State
Event
Initial state
button2Pressed
button12Pressed
IncrementHrs
BlinkHours
Transition
button1Pressed
button2Pressed
button12Pressed
IncrementMin.
BlinkMinutes
button1Pressed
button2Pressed
button12Pressed
BlinkSeconds
IncrementSec.
Final state
StopBlinking
Statecharts represent behaviour as states and
transitions
22
Other UML Notations
  • UML provide other notations
  • Implementation diagrams
  • Component diagrams (BD Chapter 7)
  • Deployment diagrams (BD Chapter 7)
  • UML includes OCL (Object constraint language)
  • Used in Design (BD Chapter 9)
  • And then there is UML 2 (a major revision of
    UML)
  • For a good introduction see
  • IBM Webcast Recorded Event Feb15 Intro.itm in
    http//developer.raindance.com/iccdoc

23
UML Core Conventions
  • Rectangles are classes or instances
  • Ovals are functions or use cases
  • Instances are denoted with underlined names
  • Examples myWatchSimpleWatch, JoeFirefighter
  • Types are denoted with non-underlined names
  • Examples SimpleWatch, Firefighter
  • Diagrams are graphs
  • Nodes are entities
  • Arcs are relationships between entities

24
Use Case Diagrams
  • Used during requirements elicitation to capture a
    systems external behaviour
  • An Actor represents a users role, that is, the
    type of a user of the system
  • A Use case represents a sequence of interactions
    for a type of functionality
  • A use case model is the set of all the use cases
    for a system and its environment, i.e., a
    complete description of all the functionalities
    of the system and its environment

25
Actors
  • An actor models an external entity which
    communicates with the system
  • User
  • External system
  • Physical environment
  • An actor has a unique name and an optional
    description.
  • Examples
  • Passenger A person using a train
  • GPS satellite A Provider of GPS coordinates to
    the system

26
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
  • Participating actors
  • Entry conditions
  • Flow of events
  • Exit conditions
  • Special requirements

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

Anything missing?
Exceptional cases!
28
The ltltextendsgtgt Relationship
  • ltltextendgtgt relationships represent exceptional or
    seldom invoked cases.
  • The exceptional event flows are separated from
    the main event flow for clarity.
  • A use case representing exceptional event flows
    may extend one or more use cases.
  • The direction of a ltltextendgtgt relationship is to
    the extended use case

29
The ltltincludesgtgt Relationship
  • ltltincludegtgt relationship represents behaviour
    that is factored out of the use case.
  • ltltincludegtgt behaviour is factored out for reuse,
    not because it is an exception.
  • The direction of a ltltincludegtgt relationship is to
    the using use case (unlike ltltextendgtgt
    relationships).

30
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 (flow of events) provide
    meat of model, not the use case diagrams.
  • All use cases need to be described (flow of
    events) for the model to be useful.

31
Class Diagrams
Enumeration getZones() Price getPrice(Zone)

  • Class diagrams represent the structure of the
    system.
  • Used
  • during requirements analysis to model problem
    domain concepts
  • during system design to model subsystems and
    interfaces
  • during object design to model classes.

32
Classes
Name
Signature
Attributes
Operations
  • A class represent a concept
  • A class encapsulates state (attributes) and
    behaviour (operations).
  • Each attribute has a type.
  • Each operation has a signature.
  • The class name is the only mandatory information.

33
Instances
zone2price 1, .20,2, .40, 3, .60
  • An instance represents a phenomenon.
  • Instance name is underlined and can show its
    class.
  • The attributes are shown with their values.
  • No operation is shown as it is the same as for
    its class.

34
Actor vs Instances
  • Difference between actor, class and instance
  • Actor
  • external to the system
  • interacts with the system
  • E.g., Passenger
  • Class
  • models an entity in the problem domain
  • modelled inside the system
  • E.g., TariffSchedule
  • Instance
  • A specific instance of a class
  • E.g., tarif_2004, the specific TariffSchedule
    being used by the passenger for purchasing a
    ticket from the ticket distributor

35
Associations
Enumeration getZones() Price getPrice(Zone)
PriceZone

  • Associations denote relationships between
    classes.
  • The multiplicity at an association end denotes
    how many objects the source object can
    legitimately reference.

36
1-to-1 and 1-to-many Associations
Has-capital
CapitalCity
Country
nameString
nameString
One-to-one association
Point
Has-vertex

Polygon
x Integer
y Integer
draw()
One-to-many association
37
Many-to-Many Associations
Company
Lists


StockExchange
tickerSymbol
1

Lists
Company
StockExchange
tickerSymbol
38
From Problem Statement To Object Model
Problem Statement A stock exchange lists many
companies. Each company is uniquely identified
by a ticker symbol

Class Diagram
Company


StockExchange
Lists
tickerSymbol
39
From Problem Statement to Code
Problem Statement
A stock exchange lists many companies. Each
company is identified by a ticker symbol
Class Diagram


Company
StockExchange
Lists
tickerSymbol
Java Code
public class StockExchange private Vector
m_Company new Vector() public class
Company public int m_tickerSymbol private
Vector m_StockExchange new Vector()

40
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.
  • A solid diamond denotes composition, a strong
    form of aggregation where components cannot exist
    without the aggregate.

Exhaust system
0..2
1
Muffler
Tailpipe
diameter
diameter
3
41
Qualifiers
  • Qualifiers can be used to reduce the multiplicity
    of an association.
  • Directory uses filename to make the association
    11

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

43
Object modelling in Practice Class Identification
Foo
Quantity
CustomerId
Deposit()
Withdraw()
GetBalance()
Class Identification Name of Class, Attributes
and Methods
44
Object modelling in Practice Encourage
Brainstorming
Foo
Quantity
CustomerId
Deposit()
Withdraw()
GetBalance()
Account
Quantity
CustomerId
Deposit()
Naming is important! Is Foo the right name?
Withdraw()
GetBalance()
45
Object modelling in Practice contd.
CustomerId
CustomerId
1) Find New Objects
2) Iterate on Names, Attributes and Methods
46
Object modelling in Practice A Banking System

Has
CustomerId
AccountId
1) Find New Objects
2) Iterate on Names, Attributes and Methods
3) Find Associations between Objects
4) Label the associations
5) Determine the multiplicity of the associations
47
Practice Object modelling Iterate, Categorize!


Has
AccountId
CustomerId()
48
Packages
  • A package is a UML mechanism for organizing
    elements into groups (usually not an application
    domain concept)
  • Packages are the basic grouping constructs with
    which you may organise UML models to increase
    their readability.
  • A complex system can be decomposed into
    subsystems, where each subsystem is modelled as a
    package

DispatcherInterface
Notification
IncidentManagement
49
Class Diagrams Summary
  • Class diagrams system structure
  • Class name, attributes (types), operations
    (signatures)
  • Instances underlined names, attribute values
  • Associations between classes, multiplicities
  • Qualified Associations from manymany to 11
  • Aggregation, composition
  • Inheritance
  • Iterate udring class identification, naming,
    attributes and methods, associations
  • Packages

50
UML sequence diagrams
  • Used during requirements analysis
  • To refine use case descriptions
  • to find additional objects (participating
    objects)
  • Used during system design
  • to refine subsystem interfaces
  • Classes are represented by columns
  • Messages are represented by arrows
  • Activations are represented by narrow rectangles
  • Lifelines are represented by dashed lines

51
Nested messages
ZoneButton
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
  • Horizontal dashed arrows indicate data flow
  • Vertical dashed lines indicate lifelines

52
Iteration condition
continued from previous slide...
ChangeProcessor

Iteration
Condition
to be continued...
  • Iteration is denoted by a preceding the message
    name
  • Condition is denoted by boolean expression in
    before the message name

53
Creation and destruction
continued from previous slide...
ChangeProcessor
Creation
Destruction
  • Creation is denoted by a message arrow pointing
    to the object.
  • Destruction is denoted by an X mark at the end of
    the destruction activation.
  • In garbage collection environments, destruction
    can be used to denote the end of the useful life
    of an object.

54
Sequence Diagram Summary
  • UML sequence diagram represent behaviour in terms
    of interactions.
  • Useful to find missing objects.
  • Time consuming to build but worth the investment.
  • Complements the class diagrams (which represent
    structure).

55
State Chart Diagrams
State
Event
Initial state
button2Pressed
button12Pressed
IncrementHrs
BlinkHours
Transition
button1Pressed
button2Pressed
button12Pressed
IncrementMin.
BlinkMinutes
button1Pressed
button2Pressed
button12Pressed
BlinkSeconds
IncrementSec.
Final state
StopBlinking
Represent behaviour as states and transitions
56
Activity Diagrams
  • An activity diagram shows flow control within a
    system
  • 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 modelled by another activity
    diagram
  • Note UML 2 uses rounded rectangles for action
    and activity nodes.

57
Statechart Diagram vs. Activity Diagram
Statechart Diagram for Incident (similar to Mealy
Automaton) (State Attribute or Collection of
Attributes of object of type Incident)
Event causes State transition
Active
Closed
Archived
Inactive
Incident- Documented
Incident- Archived
Incident- Handled
Activity Diagram for Incident (similar to
Moore) (State Operation or Collection of
Operations)
Triggerless Transition
Completion of activity causes state transition
58
Activity Diagram modelling Decisions
59
Activity Diagrams modelling Concurrency
  • Synchronisation of multiple activities
  • Splitting the flow of control into multiple
    threads

Splitting
Synchronisation
  • Now Read BD Chapter 2
Write a Comment
User Comments (0)
About PowerShow.com