Re: Enums: Properties vs. Methods
On 30 Mrz., 21:40, markspace <-@.> wrote:
On 3/30/2011 11:06 AM, Robert Klemme wrote:
Actually I always have a hard time distinguishing those two patterns:
IMHO they are pretty much identical at the core,
They're very different. State is for implementing state machines.
Strategy is for extensibility.
The biggest difference, to me, is that if I were implementing a State
pattern, I'd treat the State class as an implementation detail and keep
it and its children private. Whereas for Strategy having a public
Strategy interface/class is the whole point.
That does make sense. On a slightly different abstraction level (the
one I presented earlier) the difference boils down to when the
delegate is changed and probably also who it does (internally,
externally).
For me the crucial bit remains to delegate work to another instance
which may change - hence I'd say they are different but certainly not
_very_ different. After all these are *patterns* and not
*implementations* so there has to be some mental transformation done
during application anyway. I find it more productive to keep the
basic feature handy than to always explicitly remember whether it's
state or strategy.
> Seehttps://gist.github.com/892503#file_valve.java
This really isn't either State or Strategy. It's just an enum with som=
e
properties. I think you mean it to be a State, so let's start there.
I never claimed it was one or the other. State and Strategy were used
to describe the case where enum methods actually do something and not
just return constant properties.
Thanks for the healthy discussion!
Kind regards
robert