Multiple choice technology programming languages

What is the difference between the abstract factory pattern and the factory method pattern?

  1. The factory method makes objects that should be used together. This is not the case for the abstract factory.

  2. The abstract factory pattern provides an interface for creating a family of objects whereas factory method provides an interface for creating one object.

  3. In the abstract factory pattern the objects that the factory makes are to be used together. This is not necessarily true in the factory method pattern.

  4. The factory method pattern is used when the class does not know the class of the object it must create. But in the abstract factory this is known in advance.

  5. The factory method and abstract factory are essentially the same pattern but two different names are used to describe them depending on the circumstances when they are implemented.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The Abstract Factory pattern creates families of related or dependent objects through a factory interface, while Factory Method creates a single object through a method. Abstract Factory is best when products need to be compatible within a family. Factory Method defers object creation to subclasses. Option B correctly captures this distinction - Abstract Factory handles multiple related objects, Factory Method handles one object at a time. Other options either reverse the definitions or incorrectly claim the patterns are essentially the same.