Statecharts Executable Visual Languages for System Development, Fall 2010.

18
Statecharts Executable Visual Languages for System Development, Fall 2010

Transcript of Statecharts Executable Visual Languages for System Development, Fall 2010.

Page 1: Statecharts Executable Visual Languages for System Development, Fall 2010.

Statecharts

Executable Visual Languages for System Development,

Fall 2010

Page 2: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

2

This lecture

• The Rhapsody semantics of statecharts

• Rhapsody basics

• Examples

• The Rhapsody tool

• Basic statecharts concepts are included for reference

Page 3: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

14

Implementation

• We will discuss the Rhapsody implementation which is object oriented– Every object can have a statechart describing

its behavior (the essence of intra-object)– In Rhapsody events are associated with an

object, but can be also sent to other objects (itsOtherObj – need to specify the connection)

Page 4: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

15

Structure vs. Behavior

• Consider the system structure and behavior

Behavior

[Statecharts]

Behavior

[Statecharts]

Structure

]OMD[

Structure

]OMD[

Page 5: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

16

Structure vs. Behavior

• Structure – objects and how they are connected– E.g. Lecturer, student, laptop

• Behavior – what can each object do, what are its states.– E.g. Stand / Sit, Standby / On / Off

• The behavioral connection between the objects is not part of the statecharts language itself.

Page 6: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

17

Rhapsody Implementation

• Rhapsody generates code (in Java / C++ / C) for all the statecharts. This code collectively can be fully executed.

• During code generation, syntax errors in the statecharts are reported.

• It is necessary to initialize the static objects, through Rhapsody configuration menu.

Page 7: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

18

Object Model Diagram

• Static structure model

• It is necessary to have a connection to refer from one object to another

• Objects can have methods, attributes

• Each object can have a statechart

Page 8: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

19

Rhapsody Statechart Syntax

• Rountangle inside a Roundtangle creates hierarchy

• Arrow connection between states, is a change in behavior. Change a transition get a behavior change.

• Let’s go to semantics…

Page 9: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

20

Start working with Rhapsody

1. Choose your language

2. Define object(s) in the OMD

3. Define statechart for an object

4. Set the configurationa. Initialize to have animation

b. Initialize object instantiation

5. Generate code from statecharts (resolve errors)

6. Compile the code (java/c++) (resolve errors)

Page 10: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

21

Start working with Rhapsody

7. Run in animation mode

8. In animation mode you can choose an object instance and open the instance of the statechart

9. Insert an event to start the behavior.

Page 11: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

22

Small Example in Rhapsody

• Add class Light

• Add On and Off states

• Generate / Compile / Run

• Add printfs and inject events

• Add animation

• View instance statechart

Page 12: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

23

Small Example in Rhapsody

Page 13: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

24

Small Example in Rhapsody

• Add Orthogonality

Page 14: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

25

Statecharts Usage

• Useful for those with systematic perspective (perhaps less for software developers)

• Consider that procedural planning is not the same as Statecharts planning.

Page 15: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

26

Modeling Tips

• Try to think what are the states, and what are the transitions.

• Operations that take time are usually better in states and not on transitions.

• In some cases to model an interaction it’s useful to have an interaction object.

• Think what is really independent to create orthogonality.

• Many ways to do the same thing – condition, additional states, actions, etc.

Page 16: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

27

Home Alarm Example

• Elaborate example with multiple objects• Includes GUI, not necessary in our projects

Page 17: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

28

Dishwasher Example

• Note: Rhapsody also has inheritance and abstract classes

Page 18: Statecharts Executable Visual Languages for System Development, Fall 2010.

Executable Visual Languages for System Development

29

Technical

• Directions, Tips, Frequently Asked Questions on the web: http://www.wisdom.weizmann.ac.il/~michalk/VisLang2011/

• After selecting a project to model, consult with one of the TAs, schedule meetings by email: michal.gordon / shahar.maoz.

• If you encounter problems (that can’t be solved using the help, the web, your friends) ask us for help by email: michal.gordon / naamah.bloch.

• Submission date for 1st project: 1.1.2011