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