UML (Unified Modelling Language) & OOP (Object Oriented Programming) Part II (Ver1.0)
UML as a Programming Language
-
Upload
ed-seidewitz -
Category
Software
-
view
306 -
download
3
Transcript of UML as a Programming Language
UML® as a Programming Language
Ed Seidewitz
Presented at the
Vienna University of Technology
3 December 2014
Copyright © 2014 Ed SeidewitzUML® is a registered trademark of the Object Management Group
1
Developers provide feedback to the architects (maybe)
Modeling is extra work (isn’t it?)
It is hard to validate the correctness of the models before development.
The developers may not follow the models, without providing feedback.
It is hard to keep the models and development artifacts in sync during development (and maintenance).
Architects give models to developers
Developers create artifacts based on the models(maybe)
Architects create the models
Copyright © 2014 Ed Seidewitz 2
There are two responses
1. Code-based developmentUse models for initial design, but then focus on code
Pro: Code is single source of “truth”
Con: Code is not as good for expressing design as models.
Copyright © 2014 Ed Seidewitz 3
There are two responses
2. Model-driven developmentUse models as the source artifacts for development
Pro: Models can be more easily understood and evolved by human developers and maintainers.
Con: Model must be detailed enough to be executable in its own right.
But is this really a “con”??
Copyright © 2014 Ed Seidewitz 4
The question Is…
If we are going to take the time to carefully design our system using UML
Structural models
Behavioral models
Then why can’t we use these directly to execute our system
Copyright © 2014 Ed Seidewitz 5
The answer is…we can!
Just add detailed behavior
But...Making models detailed enough for machine execution defeats the purpose of models for
human communication.
Executable models can still be more understandable than executable code.
(Non-executable models are still useful, too.)
Copyright © 2014 Ed Seidewitz 6
The answer is…we can!
UML is not specified precisely enough to be executed (at least not in a standard way).
Just add detailed behavior
But...
The Foundational UML (fUML) standard specifies precise semantics for an executable subset of UML.
Copyright © 2014 Ed Seidewitz 7
The answer is…we can!
Graphical modeling notations are not good for detailed programming.
Just add detailed behavior
But...
The Action Language for fUML (Alf) standard specifies a textual action language with fUML semantics.
Copyright © 2014 Ed Seidewitz 8
Example: Property Management SOA
Graphical UML notation for
Data model
Message model
Interface and class models
Component models
Textual Alf notation for
Operation methods
Copyright © 2014 Ed Seidewitz 9
Service Provider Component
Copyright © 2014 Ed Seidewitz 14
Composite structure and ports are not in fUML, but
they are in the Precise Semantics of Composite
Structure (PSCS) extension.
Operation method: establish
Copyright © 2014 Ed Seidewitz 15
/** Establish a new property record. */
activity establish (
in request: 'Property Record Establishment',
out reply: 'Property Management Success Reply' [0..1],
out error: 'Error Reply' [0..1] ) {
identifier = this.'property identifier factory'.'get next identifier'();
if (request.'property type' == 'Property Type'::personal) {
property = new 'Personal Property'::'create property'(identifier,request.name);
} else {
property = new 'Real Property'::'create property'(identifier,request.name);
}
reply = this.'create reply'(request.identifier, property);
}
Operation methods are specified as UML
activities.
Newly created objects persist at the current
execution locus.
Names can have spaces or other
special characters.
Operation method: update
Copyright © 2014 Ed Seidewitz 16
/** Update the data of a property other than acquisition or disposition. */
activity update (
in request: 'Property Record Update',
out reply: 'Property Management Success Reply' [0..1],
out error: 'Error Reply' [0..1] ) {
property = Property -> select p (p.identifier == request.'property identifier');
if (property -> isEmpty()) {
error = new 'Error Reply' (
identifier => request.identifier + "/error",
'request identifier' => request.identifier,
'error code' => "PRU-001",
'error message' => "Property not found." );
} else if (property.status == 'Property Type'::disposed) {
…
} else {
if (request.'property location' -> notEmpty()) {
location = Location -> select loc
(loc.identifier == request.'property location');
'Property Location'.createLink(property, location);
}
…
}
}
A “select” maps to a concurrent expansion
region over a class extent.
Creating a link automatically establishes a bidirectional
relationship.
The models are validated in a development/test environment
We can program in UML!
The models are deployed in a production environment
Developers create fully executable models
Developers iteratively execute, test and update the models
Copyright © 2014 Ed Seidewitz 17
Agile development…with executable models!
But why UML?
UML…
Allows abstractions closer to theproblem domain
Is already familiar to developers fordesign
Has widely available tooling
© 2014 Ed Seidewitz 18
Multi-core processing is the future
1
10
100
1 000
10 000
100 000
1 000 000
10 000 000
1975 1980 1985 1990 1995 2000 2005 2010
Transistors(1000s)
Clock (MHz)
Copyright © 2014 Ed Seidewitz 19
Why is multi-core hard?
Traditional processor architectureSingle processor
Local registers / cacheRemote memory
Traditional programming languageFunctions / proceduresLocal variables / stack
Heap memory
Traditional modeling languageThings / Relationships
Events / BehaviorsCommunication
Automaticcompilation
Humanimplementation
Copyright © 2014 Ed Seidewitz 20
Why is multi-core hard?
Traditional processor architectureSingle processor
Local registers / cacheRemote memory
Traditional programming languageFunctions / proceduresLocal variables / stack
Heap memory
Traditional modeling languageThings / Relationships
Events / BehaviorsCommunication
Multi-core processor architectureMany processors
Much local memoryGlobal memory (?)
Concurrency is natural here
Concurrency is natural here
Concurrency is NOT natural here!
Copyright © 2014 Ed Seidewitz 21
from Oracle presentation “Divide and Conquer Parallelism with the Fork/Join Framework”
What makes it easier?
Result solve(Problem p) {if (p.size() < SEQUENTIAL_THRESHOLD
{ return p.solveSequentially();
} else { Result left, right; INVOKE-IN-PARALLEL { left = solve(p.leftHalf()); right = solve(p.rightHalf());
} return combine(left, right);
}}
Pseudo-codeDivide and conquer (fork/join)
Copyright © 2014 Ed Seidewitz 22
from Oracle presentation “Divide and Conquer Parallelism with the Fork/Join Framework”
What makes it easier?
Result solve(Problem p) {if (p.size() < SEQUENTIAL_THRESHOLD
{ return p.solveSequentially();
} else { Result left, right; INVOKE-IN-PARALLEL { left = solve(p.leftHalf()); right = solve(p.rightHalf());
} return combine(left, right);
}}
class SolutionTaskextends
RecursiveAction {Problem p;SolutionTask(
Problem p) {…}void compute() {SolutionTask left =
new SolutionTask(…);SolutionTask right=
new SolutionTask(…);
invokeAll(left, right);
JavaDivide and conquer (fork/join)
Copyright © 2014 Ed Seidewitz 23
What makes it easier?
Result solve(Problem p) {if (p.size() < SEQUENTIAL_THRESHOLD
{ return p.solveSequentially();
} else { //@parallel{ left = solve(p.leftHalf()); right = solve(p.rightHalf());
} return combine(left, right);
}}
solve(in p: Problem): Result {Alf UML
«structured»
«structured»
«structured»
Divide and conquer (fork/join)
Copyright © 2014 Ed Seidewitz 24
What makes it easier?Bulk data (select/map/reduce)
data->select x (filter(x))->collect x (map(x))->reduce combine
Alf
map
«parallel»
filter
«parallel»
«reduce»combine
UMLCopyright © 2014 Ed Seidewitz 25
What makes it easier?Asynchronous objects (actors)
GetAuthorization
ChargeApproved
new CreditCardCharge
ChargeApprovedChargeDenied
Copyright © 2014 Ed Seidewitz 26
But why UML?
Why not
Clojure
Scala F++
HaskellErlang
These all require new ways of thinking about coding
…
Copyright © 2014 Ed Seidewitz 27
But why UML?
UML…
Allows abstractions closer to theproblem domain
Is already familiar to developers fordesign
Has widely available tooling
Copyright © 2014 Ed Seidewitz 28
Deals with concurrency in the
UML as a Programming Language
© 2014 Ed Seidewitz 29
LieberLieber AM|USE for Sparx Enterprise Architect
http://www.lieberlieber.com/model-engineering/amuse
NoMagic Cameo Simulation Toolkitfor MagicDraw
https://www.magicdraw.com/simulation
Moka Model Execution Enginefor Eclipse Papyrus (open source)
https://wiki.eclipse.org/Papyrus/UserGuide/ModelExecution
UML as a Programming Language
© 2014 Ed Seidewitz 30
fUML Open Source Reference Implementationhttp://fuml.modeldriven.org
(see also http://www.modelexecution.org)
Alf Open Source Reference Implementationhttp://alf.modeldriven.org
Unified Modeling Languagehttp://www.uml.org
@seidewitz