dimanche 5 avril 2020

Design pattern with one class and 2 subclasses but without using inheritance

I need implements a class with 2 subclass, the main class contain variable id, the mainclass sends variable to 2 subclass, In first subclass it can change value of variable and the mainClass needs to know. The second subclass looks for the value id in database changed for first subclass. I can´t use inheritance because later i will use other second main class and i will need to use the two subclass.

I need to use a design pattern I don't know whick is.

Here my code example.

//Main app
public class App {
    public static void main(String[] args) {
        MainPanel panel = MainPanel(20);
    }
}

//Main panel
public class MainPanel {
    int id;

    public MainPanel(int id){
        this.id = id;
    }
}

//Subpanel Person
public class SubPanelPerson {
    int id;

    public SubPanelPerson() { }

    public void changeValue() {
        this.id = 30;
    }
}

//Subpanel member
public class SubPanelmember {
    int id;

    public SubPanelMember() {}

    public void findMember() {
        find(id);
    }
}

Aucun commentaire:

Enregistrer un commentaire