No Lifecycle

For really simple PicoContainer compatible components, you would not bother with a lifecycle beyond Instantiation and Garbage Collection - both of which are consequences of basic use of say DefaultPicoContainer.

Simple lifecycle - LifecyclePicoAdapter

With LifecyclePicoAdapter, we have provided a very simple set of interfaces for start(), stop() and dispose()....



The LifecyclePicoAdapter honors the classic lifecycle concepts for components.  These are start(), stop() and dispose().  If any of the components implements one of the applicable interfaces, the calling of the same method on th econtainer ( post instantiateComponent() ) will find that the call is pecolated though to it.  The container is forgiving, as it is just fine if some of none of the components contained are Startable etc.



Suitable components :



public Peach implements Startable, Stoppable, Disposable {
   public void start() { }
   public void stop() { }
   public void dispose() { }
}
public Kiwi implements Stoppable {
   public void stop() { }
}

A component that needs adaption ...



public BananaImpl implement Banana {
   public void banana() {}
   public void start() { }
   public void stop() { }
}
public BananaExtender extends BananaImpl 
    implements Startable, Stoppable{
}

Or...



public BananaDelegate implements Banana, Startable, Stoppable {
    private Banana realBanana = new BananaImpl();
    public void start() {
        realBanana.start();
    }
    public void stop() {
        realBanana.stop();
    }
} 

Custom lifecycles

Custom lifecycle management is a common requirement for components. Probably because it is so crucial there are many competing implementations, and each has its own passionate group of advocates.

Pico tries to avoid controversy by being completely agnostic about the lifecycle/lifecycles that it supports. Pico does have an implementation of a simple lifecycle (see org.picocontainer.lifecycle and PicoLifecyleAdapter) but this is there only as a convenience.

Instead of mandating a single restrictive lifecycle, Pico provides hooks that allow you to plug in almost any concievable lifecycle (or for that matter any other 'aggregated' behaviour).  As it happens the PicoLifecycleAdapter uses the getCompositeComponent() feature of PicoContainer.