commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: [chain] no chain iterator?
Date Sun, 12 Oct 2003 19:28:04 GMT
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 



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message