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]



Reply via email to