executable uml modeling in txtuml
TRANSCRIPT
Executable UML modeling in txtUML
Agenda
● Part I: Introduction● Part II: Class modeling● Part III: State modeling● Part IV: Executable modeling● Part V: Component modeling
Part I: Introduction
Webpage of the toolto be used for this course:
txtuml.inf.elte.hu/
What is modeling?
Abstraction
Software modeling:We use abstractions of real-world objects and notions
in the software programs.We help understanding with graphical diagrams.
What is UML?
● UML = Unified Modeling Language– Standardized modeling language (OMG)– It defines the semantics (= meaning) of model elements, the
ways they can be used and their graphical format– Usage:
business processes, planning of systems and software
Executable UML
● UML is most often used for planningplanning. The plans are then implemented in a programming language (C++, Java, Python, …).
● However, UML is applicable for executable modeling.“The model is the software.”
● Development environments:– BridgePoint: xtuml.org– Papyrus: eclipse.org/papyrus/– txtUML: txtuml.inf.elte.hu
txtUML
● txtUML: Textual, executable, translatable UML– Textual description of models– Generated diagrams– Model execution, debugging possibilities– C++ code can be generated (in progress)
● Developed and maintained by the “Model Driven Development Research Group” at ELTE University, Faculty of Informatics
● Web: txtuml.inf.elte.hu● It is an open source project:
github.com/ELTE-Soft/txtUML
Part II: Class modeling
Object, class
PushOpen
Welcome
Attributes
Operations
Object, class
PushOpen
Welcome
Attributes
Operations
Objects
Class
Class definition in txtUML
Base types: int, boolean, String
Association
Name of association
Role name
“A poem is written byexactly onepoet.”
“A poet can haveany number ofpoems.”
Role name
Multiplicities
Association in txtUML
Association examples
Composition
He wheels are integral partsof a car!
Exactly 4 wheels.
A wheel is mounted onat most one car.Wheels that are not mountedare allowed.
Multiplicity at the container iseither 1 or 0..1.
Composition in txtUML
Generalization
Generalization in txtUML
Class modeling example● Does this model allow
homeless persons?
● How many addresses can a person have?
● Do all family houses have kitchen and garden?
● Can a flat have a garden?
● Can 100 persons live in one single flat?
● Do all gardens have an address?
Class modeling example● Does this model allow
homeless persons?
● How many addresses can a person have?
● Do all family houses have kitchen and garden?
● Can a flat have agarden?
● Can 100 persons live in one single flat?
● Do all gardens have address?
NO
NO
NO
1
YES
NO
Diagram generation using txtUML
● Model + Diagram description ==> Graphical diagram
Diagram generation using txtUML
● The diagram descriptions are Java classes with annotations.● These are not parts of the model, should be placed in a different package.● Available annotations:
– @Show(A.class): “Should be in the diagram, but it does not matter where.”– @Row({A.class, B.class, … }): “In one row.”– @Column({A.class, B.class, … }): “in one column.”– @Left(from = A.class, val = B.class): “B is the left neighbour of A.”– @Right, @Below, @Above: similarly– @Diamond(top = A.class, right = B.class,
bottom = C.class, left = D.class): “Organized in a diamond shape.”– …
● Generation: txtUML menu / Generate diagrams from txtUML
Part III: State modeling
State machineThe class containing the state machine
Initial state
State machine
Initial transition TransitionSignal
State machine in txtUML
Guards
Choice state
Composite states
Composite states in txtUML
What is the problem?
A safer microwave oven :)
State machine diagram generationusing txtUML
The class owning thestate machine.
● Generation:txtUML menu / Generate diagrams from txtUML
Part IV: Executable modeling
Action code
● Action code is a sequence of instructions that are executed when the model is in a given situation.
Location of action code When is it called?
Operation body Operation call
Entry action State machine enters the state
Exit action State machine leaves the state
Effect The transition is executed
Action code examplesOperation(constructor of theMicrowaveOven class)
Entry and exit actionsof a state.
Effect of a transition.
Action code elements
● Local variable definition– int x = 10;– Lamp lamp;
● Value assignment– x = 11;– lamp = otherLamp;
● Basic arithmetic and logic– boolean b = (x < 11) && !(x <= 0)
Action code elements
● Accessing attributes of a class– int x = lamp.serialNumber;
● Operation call– lamp.setSerialNumber(111222);
● Accessing attributes of a signal(in entry, exit or effect)– int x = trigger.data + trigger.otherData
● Control statements– if, for, while (like in Java)
Action code elements
● Object instantiation– Lamp lamp = create(Lamp);
● Starting the state machine of an object– start(lamp);
● Object deletion– delete(lamp);
● Signal sending– send new LampOff() to lamp;– send new SignalWithData(1,false) to myObject;
Action code elements
● Linking objects through an association– link(MicroHasLamp.lamp, myLamp,
MicroHasLamp.micro, myMicro);
● Unlinking objects– link(MicroHasLamp.lamp, myLamp,
MicroHasLamp.micro, myMicro);
Associationends
Objectsto be linked
Action code elements
● Association navigation– Collection<Lamp> lamps = micro->(MicroHasLamp.lamp);
● Selecting one element from the collection– Lamp oneLamp = lamps.selectAny();
● Number of elements in a collection– int num = lamps.count();
● Iteration over the elements– for(Lamp item in lamps) { … }
Starting a model from Java code
● To be completed...
Part V: Component modeling
● To be completed...