0

I am new to java singleton, I want to make my class singleton, so that I have one instance of it in my code. The class which I want to be singleton is extend another class which its constructor have two entry.

Below code is, what I have done! but it is not correct! how can I write my singleton

public class Singleton extends Parent{
private Ui ui;
private Store store;
private singleton(Ui ui, Store store) {
    super(ui, store);
    // TODO Auto-generated constructor stub
}
private static class singletonHolder() {
    // My problem is here: how to set value for super class?!
    public static final singleton INSTANCE = new singleton();
}

public static singleton getInstance() {
    return singletonHolder.INSTANCE;
}

protected Object readResolve() {
    return getInstance();
}
public void SetStore(Store dstore){
    store = dstore;
}
public void SetUi(Ui uid){
    ui = uid;
} 
}
Rockstar
  • 2,228
  • 3
  • 20
  • 39
user90
  • 73
  • 3
  • 13
  • Do you want just **one** object of this type (a *real* singleton)? In which case there must be a single value for `ui` and `store` it should have. Alternatively, are you actually looking for a [Multiton](http://en.wikipedia.org/wiki/Multiton_pattern) (one for each unique `ui` and `store`) in which case there are posted solutions already on SO - e.g. [here](http://stackoverflow.com/a/18149547/823393). – OldCurmudgeon Jul 28 '14 at 09:26
  • yes, I want just one object, and entries are also singleton! – user90 Jul 28 '14 at 11:47

0 Answers0