vendredi 11 janvier 2019

Is creating a "master-class" considered using a singleton or something else?

I want to know if code, containing a "master-class"(A class that should have only one instance) is considered implementing the "Singleton" design pattern or if there is another design pattern that follows this concept.

I created a class "GUI" and a class "MasterControl" The class "MasterControl" defines alot of methods that interact with the GUI and contains a single "GUI" Instance on which it operates.

Code to demonstrate the basic idea.

public static void main(String[] args){
    MasterControl controller = new MasterControl();
}

public class MasterControl{
    private GUI Servant;

    public MasterControl(){
        Servant = new GUI(this);
    }
}

public MasterControl(){
    Servant = new GUI(this);
}

public class GUI{
    GUIComponent c;
    MasterControl master;

    public GUI(MasterControl master){
        this.master = master;
        c = new GUIComponent(master);
    }
}
//And so on

Aucun commentaire:

Enregistrer un commentaire