public static void main(String[] args) {
Animal a1 = new CatFactory().getAnimal();
Animal a2 = new DogFactory().getAnimal();
Animal a3 = new SnakeFactory().getAnimal();
}
}
class Animal {}
class Cat extends Animal {}
class Dog extends Animal {}
class Snake extends Animal {}
interface AnimalFactory {
Animal getAnimal();
}
class CatFactory implements AnimalFactory {
@Override
public Animal getAnimal() {
return new Cat();
}
}
class DogFactory implements AnimalFactory {
@Override
public Animal getAnimal() {
return new Dog();
}
}
class SnakeFactory implements AnimalFactory {
@Override
public Animal getAnimal() {
return new Snake();
}