"Jamis Buck" <jgb3 / email.byu.edu> schrieb im Newsbeitrag
news:412A0746.30200 / email.byu.edu...
> Robert Klemme wrote:
> > "Jamis Buck" <jgb3 / email.byu.edu> schrieb im Newsbeitrag
> > news:412893BB.1050506 / email.byu.edu...
> >
> >>Either of those patterns would have worked as well. The state-based
> >>approach (which you demonstrated) is especially compelling. Although, I
> >>think I like the module-based approach because it eliminates the need
> >>for (1) extra state information (like the @state variable) and (2)
> >>condition testing (like the 'pre' method), which could become expensive.
> >
> >
> > It shares (2) with strategy/state pattern but with the added advantage
of
> > saving a method call (the delegation).  In fact, the longer I think
about it
> > the more I like the module approach because it is very similar to the
state
> > pattern but saves the overhead (you named it) - if only there would be a
way
> > to unextend a module.  That's really the biggest showstopper for using
> > mixins to implement state pattern.  Darn...
>
> Hmm. What about some kind of "toggle!" method, which would dynamically
> re-alias a method between two different implementations? It's not as
> nice as mixins, but it gives the same effect, more or less...

That certainly could be made to work - the downside is IMHO that it tripes
your state dependend methods if you have two states: you need the impl for
state 1 and for state 2 plus the aliasing place.  That works exactly
opposite to what state pattern tries to achieve, a minimized number of
shorter methods per class.

> Or... can you dynamically create a new module with the desired
> functionality and extend your object with that? Hmm...
>
> >>"I use octal until I get to 8, and then I switch to decimal."
> >
> >
> > How do you get to "8" in octal?  Is there a new variant "octal plus"
that
> > has other digits than 0,1,2,3,4,5,6,7? :-)
>
> :) That's the idea. It was a quote of a coworker of mine explaining
> (facetiously) why he prefers the decimal base to the octal base.

:-))

Kind regards

    robert