PDA

View Full Version : Different between Singleton Model and Using Registry?



shingocat
10 May 2012, 11:14 PM
Hi Everyone,
Could some one tell me the different between using Singleton model and Using Registry? Looking like the following example.


//First way
public class SingletonContentPanel extends ContentPanel{
//singleton model instance
private fianl static ContentPanel singletonContentPanel = new SingletonContentPanel();
//other class fields
public ContentPanel getSingletonContentPanel(){
return singletonContentPanel;
}


private SingletonContentPanel(){
//do some default setings
//such as layout
}


//other method including onRender method
}


//using in other container
//singleton model way
public class TestSingleModelContentPanel extends ContentPanel{


public TestContentPanel(){
this.setLayout(new FitLayout());
}


protected void onRender(Element parent, int index){
this.add(SingletonContentPanel.getSingletonContentPanel());
}


}


//Second way


//using in other container
//using GXT Registry class
public class TestRegistryContentPanel extends ContentPanel{

private ContentPanel subContentPanel;

public TestRegistryContentPanel(){
this.setLayout(new FitLayout());
subContentPanel = new ContentPanel();
//using Registry class, we could retrieve this instance in other place in client side code
Registry.register("ContentPanel_Test",subContentPanel);
}


protected void onRender(Element parent,int index){
//now we could get the ContentPanel instance and use in here
this.add(Registry.get("ContentPanel_Test");
}
}


Do someone what different between them?
Thanks!