我有一个继承结构,类似于这样:
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;
}
}
所有对象都扩展了JButton。 还有更复杂的对象,它们扩展了ImageButton类等。我考虑使用抽象工厂模式,但我的问题是,每个类的构造函数采用不同的属性。
我应该使用哪个模式来实现良好的创建方式?