jeudi 23 avril 2020

Which design pattern for creation of inheritance objects?

I have multiple objects in an inheritance structure like this:

public class ImageButton extends JButton {
    private Image image;

    public ImageButton(Image i) {
        this.image = i;
    }
}

public class ColorButton extends JButton {
    private Color color;

    public ColorButton(Color c) {
        this.color = c;
    }
}

All objects extend JButton. There are more complex objects that extend the ImageButton class and so on. I thought to use Abstract Factory Pattern, but my problem is, that the constructors take different attributes for each class.

Which pattern can I use to realize a good way of creation?

Aucun commentaire:

Enregistrer un commentaire