You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Matthew Firth <co...@matthew.matera.net.au> on 2003/10/12 14:38:12 UTC

[chain] no chain iterator?


Has anybody considered a chain iterator?

i.e. For some chain, I'd like to be able to traverse each of its commands 
from first to last (in the usual manner, whereby the chain supplies a 
java.util.Iterator that returns each of its commands in turn).


I'm not sure if it's a sufficiently common use to support adding a method to
the actual Chain interface... but at least add it to ChainBase?


If people have any suggestions as to which way to head I'll try and draft a 
patch for it.


matthew


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [chain] no chain iterator?

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Matthew Firth wrote:

>Has anybody considered a chain iterator?
>
>i.e. For some chain, I'd like to be able to traverse each of its commands 
>from first to last (in the usual manner, whereby the chain supplies a 
>java.util.Iterator that returns each of its commands in turn).
>  
>

Why do you need to do this yourself?  The point of the Chain is to 
execute the relevant Commands for you.

>I'm not sure if it's a sufficiently common use to support adding a method to
>the actual Chain interface... but at least add it to ChainBase?
>  
>
Nothing like this should be added to the Chain interface itself -- that 
would be exposing internal details that should be of no interest to 
external parties.  The Chain, like any Command, should be viewed (from 
the outside) as a black box.

In addition, it would be redundant to add this to ChainBase because it 
is trivially simple to add in your own subclass of ChainBase (since the 
commands array is protected, not private).  As the name "Base" implies, 
this class is designed to be the *base* class for your own custom Chain 
implementations, not necessarily the standard implementation that 
everyone uses (although I haven't needed anything fancier in my work 
with commons-chain so far).

>If people have any suggestions as to which way to head I'll try and draft a 
>patch for it.
>  
>

IMHO, the only code that should have access to the list of Commands in a 
Chain is the Chain implementation itself, or the unit tests for the 
Chain implementation (which is why the package private getCommands() 
method exists).  I would consider any other code that wants to mess 
around with the internals of the chain as a potential danger signal that 
you're not respecting the abstractions of the Chain of Responsibility 
pattern.

>
>matthew
>  
>

Craig



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org