public interface Food {
public void eat();
}
public class Cake implements Food {
public void eat() {
System.out.println("------Cake.eat()----------");
}
}
public class Pissa implements Food {
public void eat() {
System.out.println("------Pissa.eat()----------");
}
}
public class FoodFactory {
private FoodFactory() {
};
private static final FoodFactory ff = new FoodFactory();
public static FoodFactory getInstance() {
return ff;
}
public Food makefood(int i) {
if (i == 1) {
Food cake = new Cake();
return cake;
}
if (i == 2) {
Food pissa = new Pissa();
return pissa;
}
return null;
}
public static void main(String[] args) {
FoodFactory.getInstance().makefood(1).eat();
}
}