抽象工厂方法模式
LandAnimal.java
public interface LandAnimal { |
WaterAnimal .java
public interface WaterAnimal { |
Cat .java
public class Cat implements LandAnimal { |
Dog .java
public class Dog implements LandAnimal { |
Fish .java
public class Fish implements WaterAnimal { |
Shark .java
public class Shark implements WaterAnimal { |
AbstractFactory .java
public abstract class AbstractFactory { |
AnimalFactory.java
public class AnimalFactory extends AbstractFactory { |
使用方法如下:
AnimalFactory factory = new AnimalFactory(); |
评论