Question

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!

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top