public class FatoryMethod {
public static void main(String[] args) {
IWorkFactory i = new StudentWorkFactory();
i.getWork().doWork();
IWorkFactory i1 = new TeacherWorkFactory();
i1.getWork().doWork();
}
}
interface IWorkFactory {
Work getWork();
}
class StudentWorkFactory implements IWorkFactory {
@Override
public Work getWork() {
// TODO Auto-generated method stub
return new StudentWork();
}
}
class TeacherWorkFactory implements IWorkFactory {
@Override
public Work getWork() {
// TODO Auto-generated method stub
return new TeacherWork();
}
}
interface Work {
void doWork();
}
class StudentWork implements Work {
@Override
public void doWork() {
// TODO Auto-generated method stub
}
}
class TeacherWork implements Work {
@Override
public void doWork() {
// TODO Auto-generated method stub
}
}
工厂方法设计模式
最新推荐文章于 2024-04-29 23:58:55 发布