Re: State pattern query



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).

.



Relevant Pages

  • Re: Beginning to Shred
    ... You should stop and make sure you have that pattern burned into your head, ... hve the Major triad at their base), then via the idea of "relative Majors ... more essential than the somewhat larger triad map (or ...
    (alt.guitar.beginner)
  • Re: m//
    ... looping over array indices is bad style in Perl. ... a loop that looks like this ... I'm guessing that it first uses map to disable pattern metacharacters in ... containing the pattern to match: ...
    (comp.lang.perl.misc)
  • State pattern query
    ... I'm attempting to use the State Pattern as described in the GoF book. ... original interface function from the Context class. ... down to the Send State subclass so it can send it out over the socket. ... now I should just use a map (which I'm using for the state transitions ...
    (comp.programming)
  • Re: Parsing File
    ... Like you, I'm not sure what the OP is trying to extract from the file, so ... The map() should really be a "for" here (you're ... pattern extraction by pattern substitution is in general not recommended. ... is a standard situation: Watch lines passing by and extract matches ...
    (comp.lang.perl.misc)
  • Re: 60C spontaneous shutdown problems
    ... pattern of behaviour. ... map showing, no route or tracking. ... gps beeps when pushing knobs but without any other response. ...
    (sci.geo.satellite-nav)