Hi,
We use the state pattern to get rid of plenty of if-if else -statements.
In each concrete state we need to access id's that can be created in any
state. All concrete states ( for this conntext) needs to access id's.
I don't want to create an instance for containing id's and pass that in the
constructor for each concreate state.
Here is a link for the pattern:
http://www.exciton.cs.rice.edu/JAvaResources/DesignPatterns/StatePat.htm
Any ideas how we can implements this?
cheers,
//mike
Daniel Pitts - 11 Oct 2007 15:24 GMT
> Hi,
>
[quoted text clipped - 4 lines]
> I don't want to create an instance for containing id's and pass that in the
> constructor for each concreate state.
Don't use IDs, let the object identity itself be the "id" of the state.
Thats one of the points of using the State pattern.
class StateFoo implements State {
public State doSomething() {
return new StateBar();
}
}
class StateBar implements State {
public State doSomething() {
return new StateFoo();
}
}
Hope this helps. If not, please clarify your problem with a short example.

Signature
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Lew - 11 Oct 2007 17:04 GMT
> Hope this helps. If not, please clarify your problem with a short example.
I.e.,
<http://www.physci.org/codes/sscce.html>

Signature
Lew
Roedy Green - 11 Oct 2007 21:18 GMT
On Thu, 11 Oct 2007 09:02:40 +0200, Mikael Petterson
<mikael.petterson@ericsson.com> wrote, quoted or indirectly quoted
someone who said :
>Any ideas how we can implements this?
Consider an enum. Each state is an enum constant. Each constant can
be initialised with magic values for that state. Each state can also
have custom implementations of various methods.
Your state tracker is a pointer to an enum constant.
Have a look at the finite state machines in the parsers used in the
JDisplay package. See http://mindprod.com/products1.html#JDISPLAY
see http://mindprod.com/jgloss/enum.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com