inf5120 ”modellbasert systemutvikling” ”modelbased system development” · deadline nov 10,...
TRANSCRIPT
-
Telecom and Informatics 1
INF5120”Modellbasert Systemutvikling”
”Modelbased System development”
Lecture 8: 04.03.2013Arne-Jørgen Berre
-
Telecom and Informatics
Content
n SoaML introductionn UML 2.0 Collaboration modelsn SoaML – Service Architecturen UML 2.0 Composite modelsn SoaML – Port/connector modelsn OCL - Object Constraint Language
n Download MagicDraw from NoMagic full EA versionn Cameo Enterprise Architecture 17.0.3 FR Enterprise Editionn http://www.nomagic.com/products/cameo-enterprise-architecture.htmln (Full license file until September 1, 2013 will be provided to each student)
2
-
Telecom and Informatics
MagicDrawCameo Enterprise Architecture
3
-
Telecom and Informatics 4
-
Telecom and Informatics 5
INF5120 - Lecture plan - 2013
n 1 (14/1): Introduction – overview Enterprise Architecture with UML and BPMN and DSLsn 2 (21/1): Service Innovation and Design, AT ONE method/workshop – myServiceFellow
(Marika Lüders)n 3: (28/1): Value Networks/VDML BPMN, vs. UML Activity diagrams - Oryxn 4 (4/2): User experience and Touchpoints/UI Design – Balsamiq – (Amela Karahasanovic)n 5 (11/2): UML and Req.Modeling –Agile User stories versus Use casesn 6 (18/2): Business-SoaML, Requirements Modeling, Goal Modeling, BMM, and Non
Functional requirementsn 7 (25/2): Model driven engineering – Metamodels, DSL, UML Profiles etc. NAV on NFR
n 8 (4/3): UML Service Modeling – SoaML, UML 2.0 Service composition, MagicDrawn 9 (11/3): Method Engineering, SW Process frameworks , SPEM/EPF, ISO 24744,
FACESEM/ESSENCE (Brian Elvesæter)n 10(18/3): Model driven engineering, transformation technologies, USDL, ISO 19119n 11(8/4): BPMN and Business Process Management and CMMN and Case Managementn 12(15/4): UML and Entity and Information modeling, UML, ISO 19103n 13(22/4): UML and Semantic models, Facts, SBVR, Ontologies, Rulesn 14(29/4): UML and Platform models, realisation, migration, Java, Apps, CloudMLn 15(6/5): MDE and DSL in practice, i.e. CloudML/ThingML – Franck Fleureyn 16(13/5): Conclusion and Summary for INF5120 - Preparation for Exam
n Exam: Monday June 3rd, 2013, (4 hours)
-
Telecom and Informatics 6
INF5120 – Oblig plan - 2013n 1 (14/1): Introductionn 2 (21/1): myServiceFellow/Service Designn 3: (28/1): Oryxn 4 (4/2): Balsamiqn 5 (11/2): Use cases 2.0n 6 (18/2): Oblig 1 – Group work
n 7 (25/2): EMF and Eclipse – Group (3) presentation – Business Model, Business-SoaMLn 8 (4/3): Oryx– Group (3) presentation - User stories/use cases, UI, NFRn 9 (11/3): Group presentation(s) on Oblig 1: User stories/use cases, UI/Balsamiq
n 10(18/3): Group presentation on Oblig 1 – NFR 1 – Parallell Start on Oblig 2 (individual)and Oblig 3 (group)
n - 22/3 : Delivery of Oblig 1n EASTER
n 11(8/4): Walk through of Oblig 1 – Questions on Oblig 2 and 3n 12(15/4): Delivery of Oblig 2 – “Value Network editor in Eclipse”n 13(22/4): Group work, Oblig 3 – Group (x) presentationn 14(29/4): Group work, Oblig 3 – Group (x) presentationn 15(6/5): Delivery of Oblig 3 – “Concierge – SA Model”n 16(13/5): Walk trough of Oblig 3 - Preparation for Exam
n Exam: Monday June 3rd, 2013, (4 hours)
-
Telecom and Informatics
SoaML Introduction
-
Telecom and Informatics
8
SoaML history
n 2006, September OMG RFPn 2007, June 3 initial submissionsn 2008 & 2009 Merge processn 2009, December SoaML 1.0 finishedn 2010, March SoaML 1.0 adopted by OMGn 2011, December SoaML 1.0 formal standard by OMG
n FTF chairs: Arne J. Berre, SINTEF and Jim Amsden, IBM
n http://www.soaml.org
8
-
Telecom and Informatics
UPMS SoaML Timeline
IssuedSeptember 29,2006
LOI DeadlineNovember 28, 2006
Initial SubmissionDeadline June 4, 2007
Voting ListDeadline August 5,2007
Revised SubmissionNovember 19, 2007
Revised SubmissionDeadline May 26,2008
OMG TechnicalMeeting June 23-27,2008 * Ontario Canada
IBM,... Fujitsu,... SHAPE,...
Adaptive,...
Revised SubmissionDeadline Aug 25, 2008
OMG Technical MeetingSept 22-26, 2008 *Orlando EEUU
OMG Technical MeetingDec 08-12, 2008 *Santa Clara EEUU
Revised SubmissionDeadline Nov 10, 2008
S1(3)
S2(2)S3(1)
S4
S5
Sx – Submission version xBx – Beta version x
SoaML FTF Feb., 2009B1
SoaML FTF Nov., 2009 SoaML FTF Rec.Dec., 2009, LosAngeles
SoaML final standardMarch, 2010 (veto, byOct. 2010)
B2
BPMN 2.0, Dec. 2009
AMP, Aug. 2009
B2
-
Telecom and Informatics
10
Metamodels and profiles
MOF
UML process genericMeta-model
real-timemodel
WorkflowMeta-model
UMLFor J2EE
migrationmodel
Workflowmodel
Migration orientedprocess Meta-model
UMLReal-time
M3
M2
M1
extension
relationship
model meta-model
relationship
-
Telecom and Informatics
11
UML/SoaML Metamodelapproach – P2
-
Telecom and Informatics
12
UML/SoaML Metamodelapproach – P3
-
Telecom and Informatics
13
SoaML/ShaML Metamodelapproach –P4
-
Telecom and Informatics
May 2009
SoaML references
n OMG Web siten SoaML Wiki: http://www.SoaML.orgn Specification:
http://www.omgwiki.org/SoaML/doku.php?id=specification
-
Telecom and Informatics
UML tools with SoaML
n MagicDraw, NoMagic
n Enterprise Architect, Sparq
n Modelio, Softeam
n RSA/RSM, IBM
n …
15
-
Telecom and Informatics
16
SoaML – Goals
n Intuitive and complete support for modelling services in UMLn Support for bi-directional asynchronous services between multiple partiesn Support for Services Architectures where parties provide and use multiple
services.n Support for services defined to contain other servicesn Easily mapped to and made part of a business process specificationn Compatibility with UML, BPDM and BPMN for business processesn Direct mapping to web servicesn Top-down, bottom up or meet-in-the-middle modellingn Design by contract or dynamic adaptation of servicesn To specify and relate the service capability and its contractn No changes to UML
-
Telecom and Informatics
17
SoaML – Scope
n Extensions to UML2.1 to support the following new modelingcapabilities:n Identifying servicesn Specifying servicesn Defining service consumers and providersn Policies for using and providing services.n Defining classification schemesn Defining service and service usage requirements and linking them to
related OMG metamodels, such as the BMM and BPMN 2.0.
n SoaML focuses on the basic service modelling conceptsn A foundation for further extensions both related to integration with other
OMG metamodels like BPMN 2.0, SBVR, OSM, ODM and others.
n SoaML is NOT a methodology
-
Telecom and Informatics
18
Definition of service in SoaML
n ”A service is value delivered to another through a well-definedinterface and available to a community (which may be the generalpublic). A service results in work provided to one by another.”
n Service Oriented Architecture (SOA) is a way of describing andunderstanding organizations, communities and systems to maximizeagility, scale and interoperability.
n SOA, then, is an architectural paradigm for defining how people,organizations and systems provide and use services to achieveresults.
n SoaML provides a standard way to architect and model SOA solutionsusing the Unified Modeling Language (UML).
-
Telecom and Informatics
19
Business Concerns
Goals
Policy
Customers
Costs
Agility
Technology SpecificationJMS, JEE, Web ServicesWSDL, BPEL, XML Schema
Technology SpecificationJMS, JEE, Web ServicesWSDL, BPEL, XML Schema
Logical System ModelTechnology Services (t-SOA),ComponentsInterfaces, Messages & Data
Logical System ModelTechnology Services (t-SOA),ComponentsInterfaces, Messages & Data
SOA in Model Driven Architecture (MDA)
Business ModelEnterprise Services (e-SOA)Roles, Collaborations & InteractionsProcess & Information
Business ModelEnterprise Services (e-SOA)Roles, Collaborations & InteractionsProcess & Information
Refinem
ent & A
utomation
Line-O
f-SightC
ompu
tatio
nIn
depe
nden
tM
odel
Plat
form
Inde
pend
ent
Mod
el
Plat
form
Spec
ific
Mod
elMDATerms
-
Telecom and Informatics
20
SoaML – Key concepts
n Services architecture – specification of communityn Participants – rolen Service contracts – collaboration (provide and
consume)n Service contract – specification of service
n Role – Provider and consumern Interfacesn Choreography (protocol, behaviour)
n Service interface – bi-directional servicen Simple interface – one-directional servicen Message Type – data exchanged between services
-
Telecom and Informatics
21
Marketplace Services – Example
Order
Conformation
Ship Req
Shipped
Shipped
PhysicalDelivery
Delivered
Status
Provider
Consumer
ProviderC
onsu
mer
Consumer
Provider
GetItThere Freight Shipper
Mechanics Are UsDealer
Acme IndustriesManufacturer
-
Telecom and Informatics
ServiceContracts andServiceArchitectures Metamodel
-
Telecom and Informatics
ServiceContracts andServiceArchitectures Profile
-
Telecom and Informatics
UML 2.0 Collaboration diagramsand SoaML
-
Telecom and Informatics
Collaboration
Start - Explanation of standard UML 2.3
-
Telecom and Informatics
Collaboration
-
Telecom and Informatics
CollaborationUse
-
Telecom and Informatics
CollaborationUse
-
Telecom and Informatics
CollaborationUse
End - Explanation of standard UML 2.3
-
Telecom and Informatics
30
Services architecture
n A ServicesArchitecture (or SOA):n is a network of participant roles providing and consuming services to fulfil a
purpose.n defines the requirements for the types of participants and service realizations that
fulfil those roles.n It is defined using a UML Collaboration.
Shippingservice
ShipStatusservice
Purchasingservice
-
Telecom and Informatics
31
Inside the Manufacturer
Order
Conformation
Shipped
Ship Req
Shipped
Delivered
Order Processing
Accounting
Service
-
Telecom and Informatics
32
Service contract
n A ServiceContract:n Fully specifies the service (terms, conditions, interfaces, choreography, etc.)n is binding on both the providers and consumers of that service.n is defined using a UML collaboration that is focused on the interactions involved in
providing a service.
n A participant plays a role in the larger scope of a ServicesArchitectureand also plays a role as the provider or user of services specified byServiceContracts.
-
Telecom and Informatics
33
Service contract
n The service contract specifies the details of the service – whatinformation, assets and responsibilities are exchanged and underwhat rules.
Rolewithinservice
Role withinservice
ServiceContract
Serviceinterfacecorresponding to role
Serviceinterfacecorresponding to role
Informationprocessed byorder processor
Informationreceived byorderer
type type
Role withinservice
-
Telecom and Informatics
34
Behaviour in SoaML can also be specified with Activity Diagrams or StateMachines.
Simple protocol choreography forOrdering service contract
-
Telecom and Informatics
35
Participants
n Participants:n represent logical or real people or organizational units that participate in services
architectures and/or business processes.n provide and use services, defining their external contract
ParticipantParticipant
-
Telecom and Informatics
Service Choreography for “Place Order”
The role of the consumer (aparticipant that places orders)and the consumers interface
The role of the provider (anorder taker) and their interface
The optional interaction torequest a quoteThe optional interaction to
return the quote
The required interaction toplace an order
The required interaction toaccept or reject the order
A more detailed look at the same service. Note that this models afully asynchronous SOA – like most business interactions, thedocument message types are detailed on the next page.
-
Telecom and Informatics
Service Data Metamodel
-
Telecom and Informatics
Service Data Profile
-
Telecom and Informatics
Message Detail for Place Order
This is the detail for the message types that correspond to theinteractions for the place order service.
Note that at the technology level this can produce XML schema forthe messages.
-
Telecom and Informatics
Example Information ModelCRR InformationModel
-
Telecom and Informatics
Linking messages to businessinformation
SOA Messages canreference and includeparts of the logicalinformation model –forming a connectionbetween SOA andenterprise data
-
Telecom and Informatics
Linking the Business Process
modeled here as a UML activity.
A business process representsthe desired behavior among thevarious participants in aservices architecture. This ismodeled here as a UML activity.
Each participant is given aswimlane which contains theactions carried out by thatparticipant within the businessprocess.
which they interact.
The overall behavior emerges asan orchestration of the actionscarried out by each of theparticipants. Interactions withparticipants must be consistentwith the service contracts bywhich they interact.
This is thebusiness processfor the “RIB ClaimsProcessing”enterprise SOA wesaw earlier.
-
Telecom and Informatics
UML 2.0 Composite diagramsand SoaML
-
Telecom and Informatics
44
Service ports and service participants
n A Service port:n is the offer of a service by one participant to others using well defined terms,
conditions and interfacesn defines the connection point through which a Participant offers its capabilities and
provides a service to clients.n It is defined using a UML Port on a Participant, and stereotyped as a
n A Service port is a mechanism by which a provider Participant makesavailable services that meet the needs of consumer requests asdefined by ServiceInterfaces, Interfaces and ServiceContracts.
-
Telecom and Informatics
45
ServiceInterfaces andParticipants Metamodel
-
Telecom and Informatics
46
ServiceInterfaces andParticipants Profile
-
Telecom and Informatics
UML Composite Diagramsn Composite Diagrams
A composite structure diagram is a diagram that showsthe internal structure of a classifier, including its interactionpoints to other parts of the system. It shows theconfiguration and relationship of parts, that together,perform the behavior of the containing classifier.
classes can be displayed as composite elements exposinginterfaces and containing ports and parts.
47
Start - Explanation of standard UML 2.3
-
Telecom and Informatics
Part
n A part is an element that represents a set of one or moreinstances which are owned by a containing classifierinstance. So for example, if a diagram instance owned aset of graphical elements, then the graphical elementscould be represented as parts; if it were useful to do so, tomodel some kind of relationship between them. Note thata part can be removed from its parent before the parent isdeleted, so that the part isn't deleted at the same time.
A part is shown as an unadorned rectangle containedwithin the body of a class or component element.
48
-
Telecom and Informatics
Portsn A port is attached to an active class.n The port has:
n A name.n An interface specifying the signals that can be received.n An interface specifying the signals that can be sent.
n Two types of ports:n Connected to internal communication channels (by
default).n Connected to the state machine for the class instance (a
behaviour port).
A behaviour port
In interface
Out interface
-
Telecom and Informatics
Composite Structure
n A composite structure diagram shows the relationship among internalcomponents of a class, in terms of communication paths.
n The class may have one or more communications ports through whichsignals can be sent or received.
n The ports are connected either to:n Internal components
n Channels connect the ports of the class to the ports of theinternal components.
n Channels can be unidirectional (one direction only) orbidirectional (both directions).
n The state machine behaviour of the class (a behaviour port).
-
Telecom and Informatics
Object instance references
instance name
class name
-
Telecom and Informatics
Composite Structure
-
Telecom and Informatics 53
Composite class (incomplete)n with parts, ports and connectors
ATM
:CardReader
:CashDispenser:Keyboard
User-Reader
User-Keyboard
ATM-bank
User-Cash
:ScreenUser-Screen
part
port
connector
-
Telecom and Informatics 54
Context Model in UML2.0 - In composite structure as part of a Collaboration
BankContext
:User :ATM :Bank
User-Reader
User-Keyboard
ATM-bank
User-Cash
User-Screen
-
Telecom and Informatics 55
Context Model in UML2.0 - II
n Including multiplicities on parts
BankContext
:User[1..10000]
:ATM[1..100] :Bank
User-Reader
User-Keyboard
ATM-bank
User-Cash
User-Screen
multiplicity
End - Explanation of standard UML 2.3
-
Telecom and Informatics
56
Service interface
n A ServiceInterface:n can type a service port.n can specify a bi-directional service
(both the provider and consumerhave responsibilities to send andreceive messages and events).
n A ServiceInterface is definedfrom the perspective of theservice provider using threeprimary sections:n provided and required Interfacesn ServiceInterface classn protocol Behavior.
-
Telecom and Informatics
57
Participant with service and request ports
n A Service Port is typed by a ServiceInterfacen A Request port is typed by a conjugate ServiceInterface (defines the use of a
service rather than its provision). This will allow us to connect serviceproviders and consumers in a Participant.
n Can be transformed to the appropriate interface/implementation code.
-
Telecom and Informatics
Interfaces for ParticipantsEach role in the servicethat receives interactionshas an interface, this isthe interface for a logicaltechnology componentand is implemented bycomponents providing orusing this service. Thisservice is bi-directional -messages flow in bothdirections.
Interfaces will correspond with parts of WSDL in a web servicesmapping of SoaML
-
Telecom and Informatics
Logical System ComponentsComponentsimplement theservice interfacesproviding the linkto systems.Participants andservices may beused in multiplearchitectures.
“Ports” on the participatingcomponents provide and requirethe service interfaces for eachservice provided or used
-
Telecom and Informatics
Composite Application Components
Components can be assembled from other components by linkingtheir services. This corresponds to the architecture for Acme.
Enterprise systems can beintegrated with adaptercomponents
Or, new implementation canbe defined inside ofcomponents.
This component is defined asa composition of othercomponents.
-
Telecom and Informatics 61
UML OCLObject Constraint Language
n The Object Constraint Languagen ISBN 0-201-37940-6
n OCL home pagen www.klasse.nl/ocl/index.htm
-
Telecom and Informatics 62
Model examples
ThiNgaminosknnndoZzzkf()karPhew(zAA)
EditortextFont
changeFont(font)addElem(elem)spellCheck()
NuclearReactorCore
add(ControlRod, int)ControlRodremove(int)
-
Telecom and Informatics 63
Precise modeling – Details in models
n Avoid misunderstandingn Completenessn Baseline for code generationn Model analysis
n Consistence among modelsn Relationships and mappings between modelsn Analysis of models
-
Telecom and Informatics 64
Simplify with OCL
Flight Airplane
CargoFlightPassengerFlight
PasssengerPlane CargoPlane1
0..* 1
0..*
0..*1flights
-
Telecom and Informatics 65
Diagram with invariants
context Flightinv: type = #cargo implies airplane.type = #cargoinv: type = #passenger implies airplane.type = #passenger
10..*Flight Airplane
type =enum{cargo, passenger}
type =enum{cargo, passenger}
flights
-
Telecom and Informatics 66
Definition of constraint
n “A constraint is a restriction on one or more values of (partof) an object-oriented model or system.”
-
Telecom and Informatics 67
Object Constraint Language - OCL
n OCL er del av UMLn Tekstlig språk for å beskrive beskrankningern Predikatlogikk gjort folkelig (ingen "$ÙÚÞ\)n Constraints
n begrensninger på modellenen multiplisitet, etc er begrensinger!
n ønsker ytterligere begrensninger
n Brukes i definisjonen av UMLs metamodelln må jo være presis!
n Formeltn entydign ingen side-effekter
-
Telecom and Informatics 68
Example model
Airport
Flight
Passenger
Airline
*
**
*
$minAge: Integerage: IntegerneedsAssistance: Boolean
departTime: Time/arrivalTime: Timeduration : IntervalmaxNrPassengers: Integer
origin
desti-nation
name: String
name: String
{ordered}
arrivingFlights
departingFlights
CEO
0..1
flights
passengers
book(f : Flight)
0..1
airline
airline
-
Telecom and Informatics 69
Constraint context and self
n Every OCL expression is bound to a specific context.n The context may be denoted within the expression using
the keyword ‘self’.
Who?Me?
-
Telecom and Informatics 70
Notation
n Constraints may be denoted within the UML model or in aseparate document.n the expression:
context Flight inv: self.duration < 4n is identical to:
context Flight inv: duration < 4n is identical to:
Flight
duration: Integerduration < 4
-
Telecom and Informatics 71
Elements of an OCL expression
n In an OCL expression these elements may be used:n basic types: String, Boolean, Integer, Real.n classifiers from the UML model and their features
n attributes, and class attributesn query operations, and class query operations
n associations from the UML model
-
Telecom and Informatics 72
OCL types
Collection
Set Bag Sequence
OclTypeReal
Integer
String Boolean
OclState
OclExpression
OclAny
-
Telecom and Informatics 73
Example: OCL basic types
context Airline inv:name.toLower = ‘klm’
context Passenger inv:age >= ((9.6 - 3.5)* 3.1).abs impliesmature = true
-
Telecom and Informatics 74
Model classes and attributes
n “Normal” attributescontext Flight inv:self.maxNrPassengers = Passenger.minAge
-
Telecom and Informatics 75
Example: query operations
context Flight inv:self.departTime.difference(self.arrivalTime)
.equals(self.duration)
Time
difference(t:Time):Intervalbefore(t: Time): Booleanplus(d : Interval) : Time
Interval
equals(i:Interval):Boolean$Interval(d, h, m : Integer) :
Interval
$midnight: Timemonth : Stringday : Integeryear : Integerhour : Integerminute : Integer
nrOfDays : IntegernrOfHours : IntegernrOfMinutes : Integer
-
Telecom and Informatics 76
Example: navigations
n Navigations
context Flightinv: origin destinationinv: origin.name = ‘Amsterdam’
context Flightinv: airline.name = ‘KLM’
-
Telecom and Informatics 77
Basic “Navigation” expressions
n i: Instructor, c: Course, s: Sessionn The name of the course:
n c.namen The date of the session:
n s.daten The instructor assigned to the session:
n s.instructorn The course of the session:
n s.coursen The name of the course of the session:
n s.course.namen The instructors qualified for the session:
n s.course.qualifiedInstructors
Instructorname
Coursename
Sessiondate
qualifiedInstructors qualifiedFor
assignedTo*
0..1*
**
Let’snavigate on amodel
-
Telecom and Informatics 78
Navigation Example
n What does a1.r1.r2.r3 yield?n Assuming the B’s have a boolean attribute “black”; black=false for b6, b8 -
what expression refers from a2 to the set { b1 }
r2a
* ** 1
0..11A B C
c1
c2
c3
c4
a1
a2
r3r1
b1b2b3b4b5b6b7b8
-
Telecom and Informatics 79
Association classes
context Person inv:if employer.name = ‘Klasse Objecten’ then
job.type = #trainerelse
job.type = #programmerendif
Person Company
Job
* 1employee employer
type : {trainer, programmer}
name : String
-
Telecom and Informatics 80
Three subtypes to Collection
n Set:n arrivingFlights(from the context Airport)
n Bag:n arrivingFlights.duration (from the context Airport)
n Sequence:n passengers (from the context Flight)
-
Telecom and Informatics 81
n OCL has a great number of predefined operations on thecollections types.
n Syntax:
collection->operation
Collection operations
-
Telecom and Informatics 82
The collect operation
n Syntax:collection->collect(elem : T | expr)collection->collect(elem | expr)collection->collect(expr)
n Shorthand:collection.expr
n The collect operation results in the collection of the valuesresulting evaluating expr for all elements in the collection
-
Telecom and Informatics 83
The select operation
n Syntax:collection->select(elem : T | expression)collection->select(elem | expression)collection->select(expression)
n The select operation results in the subset of all elementsfor which expression is true
-
Telecom and Informatics 84
The forAll operation
n Syntax:collection->forAll(elem : T | expr)collection->forAll(elem | expr)collection->forAll(expr)
n The forAll operation results in true ifexpr is true for all elements of thecollection
-
Telecom and Informatics 85
The exists operation
n Syntax:collection->exists(elem : T | expr)collection->exists(elem | expr)collection->exists(expr)
n The exists operation results in true ifthere is at least one element in thecollection for which the expression expris true.
-
Telecom and Informatics 86
Example: exists operation
context Airport inv:self.departingFlights ->
exists(departTime.hour < 6)
-
Telecom and Informatics 87
Other collection operations
n isEmpty: true if collection has no elementsn notEmpty: true if collection has at least one elementn size: number of elements in collectionn count(elem): number of occurences of elem in collectionn includes(elem): true if elem is in collectionn excludes(elem): true if elem is not in collectionn includesAll(coll): true if all elements of coll are in collection
-
Telecom and Informatics 88
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
-
Telecom and Informatics 89
OCL — Navigation Details
n An association end with cardinality maximum > 1 yields a set orsequencen anInstructor.Session yields a sequencen anInstructor.qualifiedFor yields a set
n An association end with cardinality maximum of 1 yields an object or aset (with zero or one elements)n aSession.Instructor yields an objectn aSession.Instructor->isEmpty yields a Boolean
*
*qualifiedFor
InstructorqualifiedFor
CoursequalifiedInstructors
Sessiondateevaluation
* {seq}
*
0..1
-
Telecom and Informatics 90
Collections use
n i: Instructorn The courses an instructor is qualified to teach
n Course.allInstances ->select ( c | c.qualifiedInstructors ->includes ( i ))n Sessions delivered by an instructor who is no longer qualified to teach it
n Session.allInstances ->select ( s | s.delivered ands.course.qualifiedInstructors ->excludes ( s.instructor ) )
n The last can be simplified significantly with “convenience” attributesn Session.allInstances ->select ( s | s.teacherNotQualified )
Instructorname
Coursename
Sessiondatedelivered
qualifiedInstructors qualifiedFor
assignedTo*0..1 *
**
Let’s navigateon a model
-
Telecom and Informatics 91
Another Invariant Formalized
Always combine formal and narrative descriptions
-- for every instructor ...Instructor::invariant-- for any courseCourse.allInstances->forAll ( c |-- if the evaluation bad
Session->select(Course=c)->forAll(s |s.evaluation = bad
-- then instructor is disqualified for courseimplies qualifiedFor ->excludes (c)) )
Instructor
Course*
*
qualifiedFor
Sessiondateevaluation
* {seq}
*
qualifiedInstructors
-
Telecom and Informatics 92
Same Invariant on Course
-- for every course ...Course::invariant-- for all sessionsSession->forAll ( s |-- if the evaluation is bad
s.evaluation = bad implies-- then the instructor is not a qualifiedinstructorqualifiedInstructors->excludes(s.Instructor) )
Instructor
Course*
*
qualifiedFor
Sessiondateevaluation
* {seq}
*qualifiedInstructors
-
Telecom and Informatics 93
Operation Specification
operation SeminarSystem::pay (in client:Client, out amount: Money)-- When you pay off an invoice
pre -- Provided the payment amount is not negative and does not-- exceed amount owed
client .balance >= amount and amount>=0post -- The balance is reduced by the amount of the payment
client.balance@pre = client.balance + amount
SeminarSystempay(client:Client, amount: Money)
Clientbalance
-
Telecom and Informatics 94
let, new: Convenient Names, New Objects
Any specification can introduce local names using let … in ...operation SeminarSystem::scheduleCourse
(client: Client, date: Date, course: Course)let ( availableInstructors =
instructors ->select (qualifiedFor(course) and availableOn(date)) )in ( -- the name “availableInstructors” can be used in pre or postpre availableInstructors ->notEmptypost -- some instructor from available instructors is assigned …
)Actions often result in the creation of a new object
let (s = Session.new) in ( -- s is a new member of Session types.client = client and s.date = date and s.course = courseand ….
)
-
Telecom and Informatics 95
OCL — Misc.
n Special wordsn @pre designates a value at the start of an operation
total = total@pre + amountn self designates the object itself
self.total = self.total@pre + amountn result designates the returned object (if any)
result = total
n Commentsn -- Two hyphens start a comment that goes through the end of line
-
Telecom and Informatics 96
OCL Tools
n Cyberneticsn ww.cybernetic.org
n University of Dresdenn www-st.inf.tu-dresden.de/ocl/
n Boldsoftn www.boldsoft.com
n ICON computingn www.iconcomp.com
n Royal Dutch NavynOthers … …
-
Telecom and Informatics 97
Conclusions and Tips
nOCL invariants allow you ton model more preciselyn stay implementation independent
nOCL pre- and postconditions allow you ton specify contracts (design by contract)n precisely specify interfaces of components
nOCL usage tipsn keep constraints simplen always combine natural language with OCLn use a tool to check your OCL
-
Telecom and Informatics 98
Discussion
n Sett dere sammen i grupper på 2-3 og diskuter følgende:n Vil OCL være et nyttig bidrag i noen av deres modeller? På hvilken
måte?n Kan dere gi eksempler fra øvingsoppgaven hvor OCL ville ha øket
presisjonen i deres modeller?
n Er det noen ulemper med bruk av OCL?
-
Telecom and Informatics 99
UML og OCL
n Skriver OCL som tilleggsdokumentasjon tilmodeller
n Skriver OCL i Constraintsn (Verktøy)problem: hvordan bruke aktivt
n forfiningn konsistensn kodegenerering
-
Telecom and Informatics 100
OclAnyx,y:OclAny; T is a OclTypex = yx < > yx.oclIsNewx.oclTypex.isKindOf(T)
x.isTypeOf(T)x.asType(T)
x and y are the same objectnot (x=y)True if x is a new instanceThe type of xTrue if T is a supertype (transitive) ofthe type of xTrue if T is equal to the type of xResults in x, but of type T.
-
Telecom and Informatics 101
OclType and operators
n Logical operators in Boolean expressionsn and, or, xor, not, implies
T is a OclTypeT.newT.allInstances
Create a new instance of type TAll of the instances of type T
-
Telecom and Informatics 102
Collection (1)
c,c2 : Collection(T); x,e:T; P:T® Boolean;f, f2: T® Objectc->size Number of elementsc->sum Sum of elements (elements must support
addition)c->count(e) Number of times e is in cc->isEmpty c->size = 0c->notEmpty not c->isEmpty
-
Telecom and Informatics 103
Collection (2)
c->includes(e) True if e is in cc->includesAll(c2) True if c2 in cc->excludes(e) True if e not in cc->exludesAll(c2) True if none in c2 is in cc->exists(P) True if an e makes P truec->forAll(P) True if P true for all e in cc->isUnique(f) True if f evaluates to different value for all e
in cc->sortedBy(f) Sequence sorted by fc->iterate(x;e=f;f2) Iterate x over c and apply f2, initialise e to f
-
Telecom and Informatics 104
Collection subtypes (1)
Applies to set and bagset, bag: Collection; e,x:T; P: T®Boolean;f, f2: T®Object
set->union(set2)set->union(bag)set = set2set->intersection(set2)set->intersection(bag)set – set2set->including(e)
-
Telecom and Informatics 105
Collection subtypes (2)
set->excluding(e)set->symmetricDifference(set2)
The set of elements in set or set2,but not in both
set->select(x|P) All elements for which P is validset->select(P) Same as set->select(self|P)set->reject(x|P) Same as set->select(x|not P)set->reject(P) Same as set->select(self|not P)set->collect(x|f) The bag of elements which results
from applying f to every member ofset
set->asSequenceset->asBag
-
Telecom and Informatics 106
Sequence
seq->append(e) seq followed by eseq->prepend(e) e followed by seqseq->subSequence(lower, upper) Subsequence in range [lower,
upper]seq->at(i) Element at position iseq->first seq->at(1)seq->last seq->at(seq->size)