Berin Loritsch a �crit :
>
> Vincent Massol wrote:
>
> > Actually, there is another example in the pdf book :
> >
> > if (initialized || disposed) {
> > throw new IllegalStateException ("Illegal call");
> > }
> > if (null == this.manager) {
> > this.manager = cmanager;
> > }
> >
> > Is it the recommended way or do you usually assume that the lifecycle is
> > enforced ? I have a feeling that you'll answer the following : it depends.
> > If you're using excalibur component manager then you don't need these checks
> > but if you're not using any component manager, you'd rather check. maybe not
> > ... let's see ... :)
> >
> > In any case, I'd like to have your opinion.
>
> Bottom line is this:
>
> You should ALWAYS explicitly enforce your contracts. This leads to secure
> components that cannot be interacted with in ways you had no intention of
> allowing.
Agree with enforcing contracts, but IMHO it would be a safer construct
to throw an IllegalStateException if the manager is already set instead
of silently ignoring it.
For this purpose, I have an ImmutablePropertyException (see attached
file) that automates this check in one line. You just have to write :
public void Compose(ComponentManager manager)
{
ImmutableProperyException.check(this.manager, manager, "Manager
already set");
this.manager = manager;
}
I'd be happy if this utility class could make its way into Avalon (but
where : framework, excalibur ?)
Sylvain.
--
Sylvain Wallez
Anyware Technologies - http://www.anyware-tech.com
ImmutablePropertyException.java
Description: application/unknown-content-type-jcreator.java
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
