/*
* 食物接口
*/
public interface Food {
public void desc();
}
public class Cocacola implements Food{
public void desc() {
System.out.println("可口可乐,酸酸甜甜就是我");
}
}
/*
* 鸡翅类
*/
public class ChickenWing implements Food {
public void desc(){
System.out.println("鸡翅香酥可口,跟老太太的裤腰似的");
}
}
public interface Creator {
public Food factor();
}
public class ChickenWingCreator implements Creator{
public Food factor() {
return new ChickenWing();
}
}
public class CocacolaCreator implements Creator{
public Food factor() {
return new Cocacola();
}
}
public class Client {
/**
* @param args
* @throws BadFoodException
*/
public static void main(String[] args){
Creator cocacolaCreator ,chickenWingCreator;
Food cocacola,chickenWing;
cocacolaCreator = new CocacolaCreator();
chickenWingCreator = new ChickenWingCreator();
cocacola = cocacolaCreator.factor();
chickenWing = chickenWingCreator.factor();
cocacola.desc();
chickenWing.desc();
}
}