【发布时间】:2013-01-09 19:19:57
【问题描述】:
假设我有以下情况 Parent 类和两个 Child 类,每个子类都向从父类继承的参数添加一个新参数。示例
public class Parent {
private int x;
public Parent(int x) {this.x = x;}
public int getX() {return x;}
public void setX(int x) {this.x = x;}
}
第一个孩子
public class FirstChild extends Parent {
private int y;
public FirstChild(int x, int y) {
super(x);
this.y = y;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
第二个孩子
public class SecondChild extends Parent{
private int z;
public SecondChild(int x, int z) {
super(x);
this.z = z;
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
}
那么我如何在这里使用工厂方法呢?,
【问题讨论】:
标签: java design-patterns factory