aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes howto draw state pattern in sequence digram Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "howto draw state pattern in sequence digram" Watch "howto draw state pattern in sequence digram" New topic
Author

howto draw state pattern in sequence digram

chihwah li
Greenhorn

Joined: Apr 23, 2010
Posts: 25

Hello,

I was wondering if the following is correct and if it could be improved, if so how?
My instance person has several states: child,teacher, artist. At this moment I draw the sequence diagram,
the succes scenario , that the child becomes a teacher. I draw an message call to itself to change the state.

and is the following correct or wrong:
Draw the states of the instance as instances with lifelines? (My first guess is that this is wrong, but I am not sure)

Cw
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 988
    
    1
chihwah li wrote:
and is the following correct or wrong:
Draw the states of the instance as instances with lifelines? (My first guess is that this is wrong, but I am not sure)


That's not how I would do it. Any one Person object should have one lifeline that shows the object's life span, regardless of the state it's in. You would show the state change as a self message. Look at figure 5 at http://www.ibm.com/developerworks/rational/library/3101.html. Instead of "determineAvailableReports()", you might have "state=Teacher"

HOWEVER...
I assume that you've programmed (or will program) Person to behave differently depending on whether it is in the Child or Teacher state. One way to achieve this is to have if/else or switch stgatements scattered throughout the Person class:


It's almost always better to capture the difference in behavior between a Child and a Teacher in a separate Role hierarchy. Person would have a Role field which was either instantiated with a Child or a Teacher object. The it just delegates various bits of behavior to whatever Role it has.



That way you will have a single Person object with its own lifeline, and the Child and Teacher objects will be separate objects, each with their own lifelines.
chihwah li
Greenhorn

Joined: Apr 23, 2010
Posts: 25

Right! I understand. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: howto draw state pattern in sequence digram
 
Similar Threads
Birthday Party Invite in Southern California
problem in sortings
Thread
Difference
State machine quick question