Re: State pattern query
- From: Kevin Mangold <kevin.mangold@xxxxxxxxx>
- Date: Tue, 31 Jul 2007 11:22:28 -0000
On Jul 28, 11:40 pm, gordon.is.a.mo...@xxxxxxxxx wrote:
Hello,
I'm attempting to use the State Pattern as described in the GoF book.
I have two states, send and receive, each will either call low level
send or recv depending on what command comes in over the sockets.
However, I've noticed using the pattern that I have to call the
original interface function from the Context class. This means when I
receive data in the Receive State subclass I have to return it all to
the calling function in the context class, then call that context
class method again so I can change the state, having to pass data back
down to the Send State subclass so it can send it out over the socket.
This seems a bit too complex. The trouble is I don't simply
send,receive,send,receive, it may be that I have to receive, send,send
etc. So I need to make sure it's done in the right order. Maybe for
now I should just use a map (which I'm using for the state transitions
anyway) and simply parse the command and use the map to decide whether
to send or receive? Any advice?
Thanks,
Gordy
Do you need to use a pattern? Some people implement a pattern just for
the sake of using a pattern. A pattern, or a specific pattern for that
matter, isn't always necessary. Sometimes it can even be a burden and
make your code more complex. From your description, a state pattern
wont help you out much. If your program had states such as
Authorization, Transaction, and Update (as in the POP3 protocol), then
a state pattern might come in handy. For simple sending a receiving,
those might be best if done in the same class (threaded class).
.
- References:
- State pattern query
- From: gordon . is . a . moron
- State pattern query
- Prev by Date: Re: Choosing a PL - What you can do or how you do it?
- Next by Date: Re: unusual makefiles - problems with rules
- Previous by thread: State pattern query
- Next by thread: Re: Question about programming and project management
- Index(es):
Relevant Pages
|