1

I read that Statechart Diagram is generally used to describe transition of an object. One of those objects is a class.

Could you give me an instance of how to generate statechart diagram showing transition of a class in OOP programming?

I've googled it before, but found nothing. The part where I'm a bit confused is where to put functions and attributes of a class in statechart diagram.

Thanks in advance!

januaryananda
  • 397
  • 1
  • 5
  • 15

1 Answers1

1

Attributes/operations are part of the transitions. You can check attributes as part of a Guard which limits transition between states. On Entry/Exit (and inside) of a state you can perform operations of the class.

Edit based on your comment:

Suppose I have a class called Teacher with two functions named getteachername() and setteachername() with one attribute named name.

You would use a state chart (in the following very trivial and silly case) if you need to implement constraints. Say that the name can only be set on a rule that allows to append a string to it if it starts with "Paul". Then you start with the state isEmpty. It has an outgoing transition modify where it goes to statePaul if the name is set to "Paul". From that state you can transit to the same state when appending something to name. From the stateOther you can only transit to the isEmpty.

Note that this is constructed, silly and non-realistic. But it shows how a state machine controls changes of attributes based on using methods of a class.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • Yes, as in UML State Machine Diagram Example [uml-diagrams.org: DICOM Hosted Application Life Cycle](http://www.uml-diagrams.org/dicom-hosted-application-uml-state-machine-diagram-example.html?context=stm-examples) and it's example neighborhood – xmojmr Feb 17 '15 at 17:20
  • I'm still confused on defining things to be in a statechart diagram. Suppose I have a class called "teacher" with two functions named "getteachername()" and "setteachername()" with one attribute named "name". So how can I generate statechart diagram based on that class? – januaryananda Feb 18 '15 at 03:19