Quantcast
Channel: What are the differences between Abstract Factory and Factory design patterns? - Stack Overflow
Viewing all articles
Browse latest Browse all 22

Answer by Ravindra babu for What are the differences between Abstract Factory and Factory design patterns?

$
0
0

1. My first question is about the abstract factory. Is its role to allow you to create families of concrete objects in (that can depend on what specific factory you use) rather than just a single concrete object?

Yes. The intent of Abstract Factory is:

Provide an interface for creating families of related or dependent objects without specifying their concrete classes.


2. Does the abstract factory only return one very large object or many objects depending on what methods you call?

Ideally it should return one object per the method client is invoking.

3. My understanding is that the factory method pattern has a Creator interface that will make the ConcreteCreator be in charge of knowing which ConcreteProduct to instantiate. Is this what it means by using inheritance to handle object instantiation?

Yes. Factory method uses inheritance.

4. Abstract Factory pattern delegate the responsibility of object instantiation to another object via composition? What does this mean?

AbstractFactory defines a FactoryMethod and ConcreteFactory is responsible for building a ConcreteProduct.

Just follow through the code example in this dzone article by by James Sugrue.

You can find more details in related SE posts:

What is the basic difference between the Factory and Abstract Factory Design Patterns?

Design Patterns: Factory vs Factory method vs Abstract Factory


Viewing all articles
Browse latest Browse all 22

Trending Articles