GofPatterns Gofpatterns  

Creational Patterns  «Prev  Next»
Lesson 9

Design Pattern Factory Module Conclusion

In this module you learned how creational patterns can help you make your programs more adaptable and dynamic. In particular, creational patterns allow you to defer many decisions about which classes are instantiated until runtime.
In the next module, you will learn about structural design patterns.
You will adjust the vehicle Product classes to use the Flyweight pattern, and you will see how nicely that pattern fits with the Factory Method used here.
You will also notice that no changes will be required outside the Product classes to accommodate the new pattern because of the Factory Method provides a clean separation.

The factory method pattern is an object-oriented design pattern to implement the concept of factories. Like other creational patterns, it deals with the problem of creating objects without specifying the exact class of the object that will be created.
The creation of an object often requires complex processes which are not appropriate to include when composing an object. The object's creation may lead to
  1. a significant duplication of code,
  2. may require information not accessible to the composing object,
  3. may not provide a sufficient level of abstraction, or
  4. may otherwise not be part of the composing object's concerns.
The factory method design pattern handles these problems by
  1. defining a separate method for creating the objects,
  2. which subclasses are able to override to specify the derived type of product that will be created.