Aseem,

Steve's certainly right on the money on how to go about 
componentizing your classes.  But there's one other alternative: 
write an Avalon wrapper for your class that handles the pertinent 
life cycle methods for you.

There are several good examples on how this can be done by writing 
Avalon wrappers for your POJOs.  Here's a good code example on how 
that can be done:

http://cvs.apache.org/viewcvs.cgi/incubator/directory/eve/trunk/frontend/eve
nt/?root=Apache-SVN

There are 3 maven projects in this component directory.  

spi - jar with the service interface and ancillary helper interfaces and
classes

pojo-impl - A simple as can be Plain Old Java Object implementation of the
service

merlin-impl - A merlin/Avalon specific wrapper around the POJO to make it
run within Merlin.

In my opinion this makes for a better separation of labor and concerns.  
You can focus on the core implementation in your POJO and anyone can 
use that no matter if they know Avalon or not.  So there is no 
learning curve at all.  On the other hand your Merlin savvy developer 
can rig it into Merlin and take advantage of all the features the 
container has to offer.  

Although Merlin-Unit is excellent I use it more to guarantee that 
my container wrapper has done what it needs to for my POJO to be 
viable in Merlin.  I don't use Merlin-Unit for lots of tests that 
have to repeatedly fire it up.  This takes to long for me (I'm 
impatient).  I prefer writing my unit tests for the core 
implementation logic against the POJO using simple JUnit tests.
 
Cheers,
Alex

> -----Original Message-----
> From: Stephen McConnell [mailto:[EMAIL PROTECTED]
> Sent: Thursday, April 15, 2004 11:15 AM
> To: Avalon framework users
> Subject: Re: best way to componentiza a class
> 
> Aseem Bansal wrote:
> > Hi,
> >
> > I want to componentize a class which right now takes some parameters in
> its constructor and that is the only constructor of the class.
> >
> > public class A
> > {
> >     A(String x, Info object, InetAddress y)
> >     {
> >    }
> > }
> >
> > So to make it a component, is there some way other than creating a
> default empty constructor and adding some setters/getters defined in the
> > service exposed by A.
> 
> You have several options:
> 
>    1. classic null constructor and implementation of
>       the contextualization phase as the context delivery
>       strategy (your implementation then grabs the String,
>       Info instance and InetAddrress from the supplied context
>       object)
> 
>       public class A implements Contextualizable
>       {
>            public void contextualize( Context context )
>            {
>                 // grab argument from context
>            }
>       }
> 
>    2. context by constructor - same as above except that the
>       context argument is supplied to the constructor as opposed
>       to a separate delivery interface
> 
>       public class A
>       {
>            public A( Context context )
>            {
>                 // grab argument from context
>            }
>       }
> 
>    3. identify and separate out services that prove the respective
>       arguments and create components that implement these services
>       then declare class A as a component with service dependencies
> 
>       public class
>       {
>            public A( ServiceManager manager )
>            {
>                 // grab service provider from manager
>                 // and get value from provider
>            }
>       }
> 
>    4. declare a custom lifecycle interface and extension
>       implementation that handles the delivery of the
>       respective arguments
> 
>       public class A implements MyArtifactDeliveryStageInterface
>       {
>            public void myArtifactDeliveryOperation(
>              String x, Info object, InetAddress y)
>            {
>                 // does stuff
>            }
>       }
> 
> All of the above of respective pros and cons - and the choice largely
> depends on what is needed to establish the String, Info, and InetAddress
> arguments.
> 
> Cheers, Stephen.
> 
> 
> --
> 
> |------------------------------------------------|
> | Magic by Merlin                                |
> | Production by Avalon                           |
> |                                                |
> | http://avalon.apache.org/merlin                |
> | http://dpml.net/merlin/distributions/latest    |
> |------------------------------------------------|
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]



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

Reply via email to