문제

The main difference between a "factory method" and an "abstract factory" is that the factory method is a single method, and an abstract factory is an object. But, sometimes I can't say what it is,for example

class Product{

}
interface Facotory{
    public Product create();
}

class FactoryA implements Facotory{
public Product create() {
    return null;
}   
}

class FactoryB implements Facotory{
    public Product create() {
    return null;
    }
}

Can you tell me it is factory method or abstract factory?Thank you!

도움이 되었습니까?

해결책

IMO, Your current example above is Factory Method.

As you have defined an interface (Factory) with a factory method (create) that allows sub classes (FactoryA and FactoryB) to decide which class to instantiate (Product derived classes).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top