I like the idea of asking the strategy if it can handle the vocabulary
type, but if you allow me to be a further burden on your mind... :-)
To me a message of "can handle" implies that multiple receivers of
said message can handle it; in other words, multiple strategies might
be able to process the specified vocabulary type. I know that's not
what your code says, but to me that is what is implied. The question
then becomes: Who takes precedence? GetStrategies() would have to
arrange the list of strategies to establish message handling priority
so that the first CanHandle() is on the strategy that needs to handle
it. This leaves things a little ambiguous in my eyes, and for this
reason I would think a factory would provide a more explicit
interface; it's saying get me *the* handler for this vocabulary type.
Anyway, in the end, it's just a different way to do it. Reading
alternate viewpoints has helped extend my understanding...
Kind regards,
Chad
On Tue, 29 Mar 2005 08:03:36 -0800, Philip Nelson <[EMAIL PROTECTED]> wrote:
> > Chain of responsibility is another option for creating them, although if the
> > strategy objects are completely different, can be added or removed
> > dynamically, or the relationship between the algorithm and the key isn't
> > fixed then the factory is generally a better option as it removes the
> > coupling between all the strategies themselves.
>
> It seems to me that CoR adds little value to the original question if I can
> remember it correctly ;-) The fact that it's a chain is not important because
> it's unlikely that the list of known processors for the various flavors of the
> document are unknown. Second, this discussion of the CoR came about because of
> desire to not have a switch statement to create the strategies.
>
> First the use of switch statment is not evil unless then list of options is
> long (I use 7-10 as a rule of thumb) and the list of options is pretty static.
> But if you want something more elegant how about this approach. Assume that
> the
> strategy pattern was used to describe the various vocabulary processors and
> that you have a list of strategies additionally described by interface
> VocabStrategy:
>
> public VocabStrategy getStrategy(string vocabularyType)
> {
> VocabStrategy[] processors = getStrategies(); //processors could be static if
> that's ok
> foreach (VocabStrategy strategy in processors)
> if (strategy.CanHandle(vocabularyType) return strategy;
> }
>
> foreach (XmlNode blah......)
> {
> VocabStrategy strategy = getStrategy(blah.<attribute or text containing
> type>);
> strategy.Process(blah.<get the correct nodes somehow>
> }
>
> This seems to be far less code than setting up either the strategies to know
> about the chain and having to delegate to the next and works perfectly, with
> all the normal provisos about not have actually coded this ;-)
>
> Philip - http://blogs.xcskiwinn.org/panmanphil
> "There's a difference between righteous anger and just being crabby" - Barbara
>
> ===================================
> This list is hosted by DevelopMentor(r) http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>
===================================
This list is hosted by DevelopMentor� http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com