Fundamentals
Ing. Gerardo Padilla Zárate
Day 4
Course Outline
1. Course presentation P
2. OO Concepts Review P
3. Introduction to UML P
4. UML Views P
5. Tool Fundamental P
Course outline (cont..)
6. Structural diagrams P
7. Behavioral Diagram P
8. Model Management Diagrams
9. UML during development process
10. UML and 4GL
11. Review and Critique
Review
Use Case Diagrams
Use Case
n A use case is a kind of classifier representing a
coherent unit of functionality provided by a
system, a subsystem, or a class as manifested
by sequences of messages exchanged among
the system (subsystem, class) and one or more
outside interactors (called actors) together with
actions performed by the system (subsystem,
class).
Use Case Diagram
n Use case diagrams show actors and use
cases together with their relationships.
The use cases represent functionality of a
system or a classifier, like a subsystem or
a class, as manifested to external
interactors with the system or the
classifier.
Actor
n A coherent set of roles that users of use
cases play when interacting with these use
cases.
n An actor has one role for each use case
with which it communicates.
Use Case Diagram
Telephone Catalog
Check
status
Place Salesperson
order
Fill orders
Establish
credit
Supervisor
Use Case Relationships
Relationship Association
n The participation of an actor in a use case;
that is, instances of the actor and
instances of the use case communicate
with each other.
n This is the only relationship between
actors and use cases.
Use Case Relationships: Association
Relationship Include
n An include relationship from use case E to
use case F indicates that an instance of
the use case E will also contain the
behavior as specified by F.
n The behavior is included at the location
which defined in E.
Use Case Relationships
Relationship Extends
n An extend relationship from use case A to
use case B indicates that an instance of
use case B may be augmented (subject to
specific conditions specified in the
extension) by the behavior specified by A.
n The behavior is inserted at the location
defined by the extension point in B, which
is referenced by the extend relationship.
Use Case Relationships
Relationship Generalization
n A generalization from use case C to use
case D indicates that C is a specialization
of D.
Actor Relationships
1 * Place
Order
Salesperson
Establish
1 *
Credit
Supervisor
Use Case Description: Change Flight
nActors: traveler, client account db, airline reservation system
nPreconditions:
• …
nAlternative courses
• If no flights are available then …
When to model use cases
n Model user requirements with use
cases.
n Model test scenarios with use cases.
n If you are using a use-case driven
method
¨ start with use cases and derive your
structural and behavioral models from it.
n If you are not using a use-case driven
method
¨ make sure that your use cases are consistent
with your structural and behavioral models.
Use Case Modeling Tips
n Make sure that each use case describes a significant chunk
of system usage that is understandable by both domain
experts and programmers
n When defining use cases in text, use nouns and verbs
accurately and consistently to help derive objects and messages
for interaction diagrams
n Factor out common usages that are required by multiple use
cases
¨ If the usage is required use <<include>>
¨ If the base use case is complete and the usage may be optional,
consider use <<extend>>
n A use case diagram should
¨ contain only use cases at the same level of abstraction
¨ include only actors who are required
n Large numbers of use cases should be organized into packages
Online HR System: Use Case Relationships
Online HR System: Update Benefits Use Case
nActors : employee, employee account db, healthcare plan system,
insurance plan system
nPreconditions:
nAlternative courses
• If health plan is not available in the employee’s area the employee is
informed and asked to select another plan...
Review: Use Case Diagrams
n What is a use case?
n What is a collaboration diagram?
n Describe the relation between Sequence
Diagram and Collaboration Diagram.
Excercise 7
Excercise 7
Model Management Diagrams
n Packages
n Subsystem
n Model
Package
n A package is a grouping of model
elements. Packages themselves may be
nested within other packages.
Customer Order
Warehouse
Location Item
B +C
-D
«import»
A +E
X Y
B Y::C +C
-D
«import»
A Y::E +E
B +C
-D
«access»
A +E
X Y
«access»
B +C
-D
A +E
Traffic
Trunk Control
Communicating subsystems
constitute a system
Subscription
Subsystem Aspects
n A subsystem has two aspects:
¨ An external view, showing the services
provided by the subsystem
¨ An internal view, showing the
realization of the subsystem
n There is a mapping between the two
aspects
Subsystem Aspects
Specification elements Realization elements
?
n The subsystem realization defines the actual contents
of the subsystem
n The subsystem realization typically consists of classes and
their relationships, or a contained hierarchy of subsystems
with classes as leaves
Subsystem Specification
?
The subsystem specification defines the
external view of the subsystem
Subsystem Specification
n The subsystem specification
¨ describes the services offered by the
subsystem
¨ describes the externally experienced
behavior of the subsystem
¨ does not reveal the internal structure of
the subsystem
¨ describes the interface of the subsystem
Specification Techniques
n The Use Case approach
n The State Machine approach
n The Logical Class approach
n The Operation approach
Initiate Call
Trunk
Receive Digit and Connect
Stopped Running
Maintenance
Error Exhausted
Number
Analyzer Dictionary
Network
Manager
Specification elements
Initiate Call
Trunk
Receive Digit and Connect
Specification elements
Traffic
Trunk Control Subscription
Traffic
Trunk Control Subscription
Operations and Interfaces
«Interface» «Interface»
Operations
operation1( ) operation2( )
operation2( ) «realize» operation1( ) : Type1 «realize» operation3( )
operation4( ) operation5( )
operation2( ) : Type2
operation3( ) : Type3
operation4( ) : Type4
operation5( ) : Type5
operation3( ) : Type3
operation4( ) : Type4
operation5( ) : Type5
«realize»
Specification elements
Initiate Call
changeDigitAnalysisInformation ( )
:
:
Trunk
Receive Digit and Connect
bAnswer :Subscription
1: markBusy
5: markBusy
Subsystem Interaction
4:receive
1:transmit
2:send
3:ack
1.4
Communicating with
Subsystems
n Two approaches:
¨ Open subsystem - public elements are
accessed directly
¨ Closed subsystem - access via the
subsystem itself
1.4
Open Subsystems
Traffic Control
n A subsystem is called
-B
open if its realization
+A is used directly by the
environment
«import»
n The specification
Trunk
acts
+TC::A ¨ as an overview of
the subsystem
-C ¨ as a requirements
specification
+B
1.4
Closed Subsystems
Traffic Control
1.4
Subsystem Instance
:Traffic Control
1.4
Diagram Tour
n Subsystems can be shown in static diagrams and
interaction diagrams
n “Fork” notation alternative for showing contents:
Realization elements
Diagram Tour – continued
n Subsystems can be shown in interaction diagrams
¨ collaboration diagrams
¨ sequence diagrams
Sequence Diagram
When to Use Subsystems
n To express how a large system is
decomposed into smaller parts
n Distributed development
n To express how a set of modules are
composed into a large system
n For component based development
Component Based Development
ShoppingCart
«Interface» ShoppingCart
ShoppingCartHome «auxiliaryClass» Home «focalClass»
«call»
HomeObject ShoppingCart ShoppingCart
create(…)
«call» Impl
findByPrimaryKey(…)
...
ArtStore «auxiliaryClass»
«call»
Client «Interface» Context
ShoppingCart
ShoppingCart DBbroker
«call» getItemCount(…)
«auxiliaryClass» «auxiliaryClass»
setItemCount(…)
getTotal(…) RemoteObject ContextObject
setTotal(…)
...
1.4
Modeling Tips – Subsystem
n Define a subsystem for each separate
part of a large system
n Choose specification technique
depending on factors like kind of system
and kind of subsystem
n Realize each subsystem independently,
using the specification as a
requirements specification
Model Management Diagrams
n Packages
n Subsystem
n Model
Model
Design Model
Core Concepts
Construct Description Syntax
Model A view of a system, with a certain
purpose determining what aspects Name
of the system are described and at
what level of detail.
Design
«trace»
Diagram Tour
n Models as such are seldom shown in diagrams
n Two equivalent ways to show containment:
Model vs. Diagram
Diagrams make up the
Use Case
documentation of a model
Model
Design
Model
When to Use Models
n To give different views of a system
to different stakeholders
n To focus on a certain aspect of a
system at a time
n To express the results of different
stages in a software development
process
Modeling Tips – Model
refined semantics
(valid) different semantics
(NOT valid)
Standard UML semantics
Models
n A model is a description of something
¨ “a pattern for something to be made” (Merriam-
Webster)
blueprint
(model)
building building
Customer CustomerOrder
item Model (M1)
id
quantity
*
Classifier
n Tagged Values
¨ individual modifiers with user-defined semantics
¨ can be attached to any meta-class or stereotype
Stereotypes
n Used to define specialized model elements based on a
core UML model element
n Defined by:
¨ Base metaclasses (or stereotype)
n What element is specialized?
¨ Constraints:
n What is special about this stereotype?
¨ required tags (0..*)
n What values does this stereotype need to know?
¨ icon
n How should I appear in a model?
n A model element can be stereotyped in multiple different
ways
1.4
Example
n Capsule: A special type of concurrent
object used in modeling certain real-
time systems
n By definition, all classes of this type:
¨ are active (concurrent)
¨ have only features (attributes and operations) with
protected visibility
¨ have a special “language” characteristic used for
code generation purposes
n In essence, a constrained form of the
general UML Class concept
Example: Stereotype Definition
Stereotype Base Class Tags Constraints
n Using a tabular form:
isActive = true;
self.feature->select(f |
«capsule» Class language f.oclIsKindOf(Operation))->
forAll(o |
o.elementOwnership.visibility
= #protected)
1.4
Stereotype Notation Stereotype
icon
n Several choices
«capsule»
aCapsuleClass aCapsuleClass
«stereotype»
«stereotype»
capsule
Tags
language : String
1.4
Heuristic: Combining Stereotypes
n Through multiple inheritance:
«stereotype»
capsule «metaclass»
Package
Tags
language : String
«stereotype»
«stereotype»
PackageCapsule
1.4
When to Use Stereotypes?
n Why not use normal subclassing instead?
n Use stereotypes when:
¨ additionalsemantic constraints cannot be
specified through standard M1-level modeling
facilities
n e.g. “all features have protected visibility”
¨ theadditional semantics have significance
outside the scope of UML
n e.g. instructions to a code generator
“debugOn = true”
Tagged Values
n Consist of a tag and value pair
n Typed with a standard data type or M1 class
name
n Typically used to model stereotype attributes
¨ Additional information that is useful/required to
implement/use the model
n May also be used independently of stereotypes
¨ e.g., project management data
(“status = unit_tested”)
1.4
Constrains
n Constraints
¨ formal or informal expressions
¨ must not contradict inherited base semantics
ATM_Withdrawal Account
customer : id customer : id
amount : Money balance : Money
{amount is multiple of $20}
«constraint»
{ATM_Withdrawal.customer =
Account.customer}
UML Profiles
n A package of related extensibility elements
that capture domain-specific variations
and usage patterns
¨A domain-specific interpretation of UML
n Profiles currently being defined by the
OMG:
¨ EDOC
¨ Real-Time
¨ CORBA
¨ ...
OCL
Use the
Object
Constraint
Language
Can we make this more
precise?
flights 1
Flight Airplane
0..*
0..*
PassengerFlight CargoFlight
0..*
1
PassengerPlane CargoPlane
1
116
Diagram with added invariants
{context Flight
inv: type = #cargo implies airplane.type = #cargo
inv: type = #passenger implies airplane.type = #passenger}
117
Definition of constraint
n “A constraint is a restriction on one or
more values of (part of) an object-oriented
model or system.”
Different kinds of constraints
n Class invariant
¨a constraint that must always be met by all
instances of the class
n Precondition of an operation
¨a constraint that must always be true
BEFORE the execution of the operation
n Postcondition of an operation
¨a constraint that must always be true AFTER
the execution of the operation
Constraint stereotypes
n UML defines three standard stereotypes
for constraints:
¨ invariant
¨ precondition
¨ postcondition
What is OCL?
n OCL is
¨a textual language to describe constraints
¨ the constraint language used in UML models
n As well as the UML meta-model
n Formal but easy to use
¨ unambiguous
¨ no side effects
Constraints and the UML model
n OCL expressions are always bound to a
UML model
¨ OCL expressions can be bound to any model
element in UML
Core OCL Concepts
n What are constraints
n Core OCL Concepts
n Advanced OCL Concepts
n Wrap up
Example model
Flight
departing
origin Flights
Airport departTime: Time
* /arrivalTime: Time flights
name: String duration : Interval
* maxNrPassengers: Integer
arriving * airline
desti-
nation Flights Airline
Passenger
$minAge: Integer
age: Integer airline 0..1
needsAssistance: Boolean 0..1
n Class attributes
context Passenger inv:
age >= Passenger.minAge
Example: query operations
context Flight inv:
self.departTime.difference(self.arrivalTime)
.equals(self.duration)
Time Interval
$midnight: Time nrOfDays : Integer
month : String nrOfHours : Integer
day : Integer nrOfMinutes : Integer
year : Integer
hour : Integer equals(i:Interval):Boolean
minute : Integer $Interval(d, h, m : Integer) :
difference(t:Time):Interval Interval
before(t: Time): Boolean
plus(d : Interval) : Time
Associations and navigations
n Every association in the model is a
navigation path.
n The context of the expression is the
starting point.
n Role names are used to identify the
navigated association.
Example: navigations departing
Flight
origin Flights
Airport departTime: Time
* /arrivalTime: Time
name: String duration : Interval
* maxNrPassengers: Integer
desti- arriving
nation Flights
context Flight
inv: origin <> destination
inv: origin.name = ‘Amsterdam’
context Flight
inv: airline.name = ‘KLM’
Association classes
context Person inv:
if employer.name = ‘Klasse Objecten’ then
job.type = #trainer
else
job.type = #programmer
Job
endif type : {trainer, programmer}
* 1 Company
Person
employee employer name : String
The OCL Collection types
n What are constraints
n Core OCL Concepts
¨ Collections
f3 airline2
airp2 f4
airline3
f5
f3
duration = 3 airline2
f4
airp2
duration = 5
airline3
f5
departing flights duration = 2
arriving flights
The forAll operation
n Syntax:
¨ collection->forAll(elem : T | expr)
¨ collection->forAll(elem | expr)
¨ collection->forAll(expr)
f3
depart = 8 airline2
f4
airp2
depart = 9
airline3
f5
depart = 8
f3
depart = 8 airline2
f4
airp2
depart = 9
airline3
f5
depart = 8
open closed
n Example:
context Airport inv:
Let supportedAirlines : Set (Airline) =
self.arrivingFlights -> collect(airLine) in (supportedAirlines -
>notEmpty) and
(supportedAirlines ->size < 500)
Iterate
n The iterate operation for collections is the
most generic and complex building block.
collection->iterate(elem : Type;
answer : Type = <value> |
<expression-with-elem-and-answer>)
Iterate example
n Example iterate:
context Airline inv:
flights->select(maxNrPassengers > 150)->notEmpty
n Is identical to:
context Airline inv:
flights->iterate (f : Flight;
answer : Set(Flight) = Set{ } |
if f.maxNrPassengers > 150 then
answer->including(f)
else
answer endif )->notEmpty
Inheritance of constraints
n Guiding principle Liskov’s Substitution
Principle (LSP):
¨ “Whenever an instance of a class is expected,
one can always substitute an instance of any
of its subclasses.”
Inheritance of constraints
n Consequences of LSP for invariants:
¨ An invariant is always inherited by each
subclass.
¨ Subclasses may strengthen the invariant.