avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Berin Loritsch <blorit...@apache.org>
Subject Re: [RT] Parameterized Lookups ?
Date Fri, 25 Jul 2003 15:09:46 GMT
Perhaps if I have a better understanding of the real problem you are trying
to solve, I might be able to better grasp what you are getting at.  For
instance, I can think of some things that would make sense for a container
to pass into a component on lookup but I have trouble in my mind coming up
with a reason to pass user variables to the component.

Keep in mind that components might be shared across instances, so what it
looks like you are proposing won't work for them.  Also, I would like to
know the scope of the parameter.  Does it apply as long as the client maintains
its reference to the component, so that after the component is released the
parameter is null and void?

Solving real problems is what will keep Avalon Framework lean and mean.  I
think we should resist changes to Avalon Framework unless there is a well
defined reason to do so, and all the committers agree.  So we need to compare
a real life example showing why it is cumbersome to do it now, and how much
easier it will be in the future if we adopt the proposal.

Marcus Crafter wrote:

> Hi All,
> 
> Hope all is well!
> 
> We all know that Avalon has super cool lifecycle management offering a way 
> to construct arbitrary components in defined manner. One limitation by 
> this though is the requirement of a zero argument constructor.
> 
> This requirement is ok for many components but sometimes I miss this
> especially when writing components that need some external data dynamically
> before they can be considered valid.
> 
> For the lack of a better example, think of a Date component that needs
> to be given a real date value before it can be used. Outside of Avalon one
> might write:
> 
> MyDate date = new MyDate("20030607");
> 
> When using Avalon however, after creation through the normal lifecycle we 
> must set the date on the component with some set* method.
> 
> MyDate date = (MyDate) m_manager.lookup(MyDate.ROLE);
> date.setDate("20030725");
> 
> This means however that the component is not valid though until an external
> (meaning non-lifecycle method) has been invoked on it, which we can't
> enforce -> meaning we have to document somewhere that a user must
> call the set* before calling any other method. 
> 
> It also means, if we're being proactive that in all of the other methods we 
> have to watch for the case when the user doesn't invoke the set* method, 
> and throw an appropriate exception, etc.
> 
> A possible way to fix this could be to offer Parameterized lookups, 
> something like:
> 
> interface ServiceManager {
> 
> 	Object lookup(String role, Object[] parameters);
> }
> 
> where 'parameters' specifies arbitrary number of parameters that can be 
> passed through to the component manager and given to the object to be 
> constructed somehow (eg. lifecycle extension, matching parameter constructor, 
> component handler, new lifecycle stage, etc).
> 
> This would let us do something like:
> 
> MyDate today = (MyDate) m_manager.lookup(MyDate.ROLE, { "20030725" } );
> 
> Thoughts anyone? Perhaps there's an even better solution out there ?
> 
> Cheers,
> 
> Marcus
> 


-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


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


Mime
View raw message