executable uml modeling in txtuml

44
Executable UML modeling in txtUML

Upload: others

Post on 23-Apr-2022

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Executable UML modeling in txtUML

Executable UML modeling in txtUML

Page 2: 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

Page 3: Executable UML modeling in txtUML

Part I: Introduction

Page 4: Executable UML modeling in txtUML

Webpage of the toolto be used for this course:

txtuml.inf.elte.hu/

Page 5: Executable UML modeling in txtUML

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.

Page 6: Executable UML modeling in txtUML

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

Page 7: Executable UML modeling in txtUML

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

Page 8: Executable UML modeling in txtUML

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

Page 9: Executable UML modeling in txtUML
Page 10: Executable UML modeling in txtUML

Part II: Class modeling

Page 11: Executable UML modeling in txtUML

Object, class

PushOpen

Welcome

Attributes

Operations

Page 12: Executable UML modeling in txtUML

Object, class

PushOpen

Welcome

Attributes

Operations

Objects

Class

Page 13: Executable UML modeling in txtUML

Class definition in txtUML

Base types: int, boolean, String

Page 14: Executable UML modeling in txtUML

Association

Name of association

Role name

“A poem is written byexactly onepoet.”

“A poet can haveany number ofpoems.”

Role name

Multiplicities

Page 15: Executable UML modeling in txtUML

Association in txtUML

Page 16: Executable UML modeling in txtUML

Association examples

Page 17: Executable UML modeling in txtUML

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.

Page 18: Executable UML modeling in txtUML

Composition in txtUML

Page 19: Executable UML modeling in txtUML

Generalization

Page 20: Executable UML modeling in txtUML

Generalization in txtUML

Page 21: Executable UML modeling 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?

Page 22: Executable UML modeling 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 agarden?

● Can 100 persons live in one single flat?

● Do all gardens have address?

NO

NO

NO

1

YES

NO

Page 23: Executable UML modeling in txtUML

Diagram generation using txtUML

● Model + Diagram description ==> Graphical diagram

Page 24: Executable UML modeling in txtUML

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

Page 25: Executable UML modeling in txtUML

Part III: State modeling

Page 26: Executable UML modeling in txtUML

State machineThe class containing the state machine

Initial state

State machine

Initial transition TransitionSignal

Page 27: Executable UML modeling in txtUML

State machine in txtUML

Page 28: Executable UML modeling in txtUML

Guards

Page 29: Executable UML modeling in txtUML

Choice state

Page 30: Executable UML modeling in txtUML

Composite states

Page 31: Executable UML modeling in txtUML

Composite states in txtUML

Page 32: Executable UML modeling in txtUML

What is the problem?

Page 33: Executable UML modeling in txtUML

A safer microwave oven :)

Page 34: Executable UML modeling in txtUML

State machine diagram generationusing txtUML

The class owning thestate machine.

● Generation:txtUML menu / Generate diagrams from txtUML

Page 35: Executable UML modeling in txtUML

Part IV: Executable modeling

Page 36: Executable UML modeling in txtUML

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

Page 37: Executable UML modeling in txtUML

Action code examplesOperation(constructor of theMicrowaveOven class)

Entry and exit actionsof a state.

Effect of a transition.

Page 38: Executable UML modeling in txtUML

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)

Page 39: Executable UML modeling in txtUML

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)

Page 40: Executable UML modeling in txtUML

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;

Page 41: Executable UML modeling in txtUML

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

Page 42: Executable UML modeling in txtUML

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) { … }

Page 43: Executable UML modeling in txtUML

Starting a model from Java code

● To be completed...

Page 44: Executable UML modeling in txtUML

Part V: Component modeling

● To be completed...