-----Mensagem original-----
De: Jonathan Hawkes [mailto:[EMAIL PROTECTED]

<snip/>

> I was thinking decorator.  But if you can explain how you would use a
> chain-of-responsibilities pattern, I would be interested.
> My intended use was something like:

<snip/>

This is cool, I'm not saying nothing against it :-)

But

- Concerns like Creation/LogEnabling/Service/Initialize should have a order
of execution.
- Container should not use instanceof or marker interfaces to differentiate
(this word exists?) Concerns and set up an execution order

So, in my head I see something like:


Container c = new Container();
c.addConcert( ExecutionStep.Creation, new DefaultAvalonCreationConcern() );
c.addConcert( ExecutionStep.LogEnable, new LogEnablingConcern() );


in response of a lookup the container will build a chain gathering all
Concerns and setting up the order. Throught the execution:



interface Concern
{
  object applyConcern(Container c, object target )
  {
  }

  void setNextConcern(Concern concern);
}

public class DefaultAvalonCreationConcern implements Concern
{
  Concern m_nextConcern;

  public void setNextConcern(Concern concern)
  {
    m_nextConcern = concern;
  }

  public object applyConcern(Container c, object target)
  {
    // Simple instantiation
    Object newObject = ...;

    // Go on with the chain
    if (nextConcert != null)
    {
      return m_nextConcern.applyConcern(c, newObject);
    }

    return newObject;
  }
}



public class LogEnablingConcern implements Concern
{
  Concern m_nextConcern;
  Logger m_root;

  public LogEnablingConcern(Logger log)
  {
    m_root = log;
  }

  public void setNextConcern(Concern concern)
  {
    m_nextConcern = concern;
  }

  public object applyConcern(Container c, object target)
  {
    if (target instanceof LogEnabled)
    {
       ContainerUtil.enableLogging( target, m_root );
    }

    if (nextConcert != null)
    {
      return m_nextConcern.applyConcern(c, target);
    }

    return newObject;
  }
}



Using this approach allows a concern to add new steps while executing. I'm
using something like that in Avalon Castle (more or less)


--
hammett





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to