dev@glassfish.java.net

[GFv3] a PerLookup component extending a Singleton component

From: Sahoo <Sahoo_at_Sun.COM>
Date: Mon, 28 Jul 2008 16:05:51 +0530

I see some interesting component inheritance pattern V3. DeployCommand
and most other AdminCommands are annotated as @Scope(*PerLookup.class*),
yet they extend ApplicationLifecycle which is annotated as
@Scope(*Singleton.class*). Every time an AdminCommand is looked up, a
new instance is created, which results in instantiation of
ApplicationLifecycle, thus violating the intended Singleton scope of
ApplicationLifecycle.
Component inheritance is very tricky, IMO. What should happen when the
base component has postConstruct()? Do you expect it to get executed? If
not, who ensures that its state is correctly initialized? What happens
when there is a scope mismatch as in the aforementioned example?
So, I think replacing inheritance by delegation would be a better
option. Any comments?

BTW, an AdminCommand extending ApplicationLifecycle sounds wrong,
doesn't it?

Thanks,
Sahoo