标签:关联 好处 str span sim work data- lang 信息
概述:
public class TestFactoryMethod {
public static void main(String[] args) {
IWorkFactory s = new StudentWorkFactory();
s.getWork().doWork();
IWorkFactory t = new TeacherWorkFactory();
t.getWork().doWork();
}
}
interface IWorkFactory {
Work getWork();
}
class StudentWorkFactory implements IWorkFactory{
@Override
public Work getWork() {
return new StudentWork();
}
}
class TeacherWorkFactory implements IWorkFactory{
@Override
public Work getWork() {
return new TeacherWork();
}
}
interface Work {
void doWork();
}
class StudentWork implements Work {
@Override
public void doWork() {
System.out.println("学生写作业");
}
}
class TeacherWork implements Work {
@Override
public void doWork() {
System.out.println("老师改作业");
}
}
标签:关联 好处 str span sim work data- lang 信息
原文地址:http://www.cnblogs.com/chendifan/p/6905031.html