package factory;
/**
* @Author ***
* @Date 2021/6/9 17:46
* @Email ***
* @Description: DOTO
*/
interface Animal1{
void call();
}
class Cat1 implements Animal1{
@Override
public void call() {
System.out.println("喵喵");
}
}
class Dog1 implements Animal1{
@Override
public void call() {
System.out.println("汪汪");
}
}
abstract class Factory{
public abstract Animal1 getAnimal1();
}
class CatFactory extends Factory{
@Override
public Animal1 getAnimal1() {
return new Cat1();
}
}
class DogFactory extends Factory{
@Override
public Animal1 getAnimal1() {
return new Dog1();
}
}
public class FactoryMethod {
public static void main(String[] args) {
new DogFactory().getAnimal1().call();
new CatFactory().getAnimal1().call();
}
}
工厂方法模式
最新推荐文章于 2024-11-10 22:06:14 发布