简单工厂又叫静态工厂方法模式
public interface FruitDemo {
void eat();
}
public class EatApple implements FruitDemo{
public void eat(){
System.out.print("eat Apple!!");
}
}
public class EatOrange implements FruitDemo {
public void eat(){
System.out.print("eat orange!!");
}
}
//创建一个工厂
public class IFruitFactory {
public static FruitDemo eatApple(){
return new EatApple();
}
public static FruitDemo eatOrange(){
return new EatOrange();
}
}
public class Test {
public static void main(String args[]) {
IFruitFactory ift = new IFruitFactory();
ift.eatApple().eat();
ift.eatOrange().eat();
}
}
简单工厂模式就是根据客户端的需要选择某一个特定的对象来实现