Creational Patterns  «Prev  Next»
Lesson 9

Design Pattern Factory Module Conclusion

Creational design patterns serve as cornerstone methodologies for object instantiation in software engineering. These patterns abstract the instantiation process, making the system decoupled, thereby ensuring that the concrete classes are isolated from the complex creation logic. This isolation is not just syntactic sugar; it brings forth architectural advantages that make applications more adaptable and dynamic. Below, each creational pattern is dissected to elucidate how they contribute to system adaptability and dynamic behavior.

Singleton Pattern

The Singleton pattern ensures a class has only one instance and provides a global point of access to that instance. By controlling resource access through a single entry point, the Singleton pattern provides a mechanism to coordinate actions across the system effectively.
  1. Adaptability: Resource Management: Singleton helps in managing resources efficiently, such as database connections, thereby adapting to resource constraints.
  2. Dynamic Behavior: Configurability: Parameters of the singleton instance can be adjusted dynamically without affecting its consumers, thus enabling dynamic behavior.

Factory Method Pattern

Factory Method defines an interface for creating an object but allows subclasses to alter the type of objects that will be created.
  1. Adaptability: Loose Coupling: By encapsulating object creation, the Factory Method permits higher-level code to be decoupled from the object types that it instantiates. This allows easier integration of new object types or substitution of existing ones.
  2. Dynamic Behavior Extensibility: New types of objects can be introduced with minimal changes to existing code, thereby making the system easily extendable.

Abstract Factory Pattern

The Abstract Factory pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes.
  1. Adaptability: Interchangeable Families of Products: Abstract Factory allows for the whole family of products to be swapped out easily, aiding the adaptability of the system to different environments or requirements.
  2. Dynamic Behavior: Dynamic Composition: Complex objects can be composed dynamically based on runtime requirements, thus providing a versatile and dynamic system architecture.

Builder Pattern

The Builder pattern provides a construct for creating a complex object step by step, often through a fluent interface.
  1. Adaptability: Parameter Variability: Builder Pattern supports the construction of a complex object with various configurations. This accommodates the adaptability needed for creating objects that have numerous possible variations.
  2. Dynamic Behavior: Immutable Objects: Once an object is constructed, it's often immutable, which is beneficial for multi-threaded environments. Yet, the builder itself can be reset or altered dynamically to construct other objects.

Prototype Pattern

The Prototype pattern creates new objects by copying an existing object, known as a prototype.
  1. Adaptability: Dynamic Loading: Prototypes can be registered and de-registered at runtime, providing the ability to dynamically load object configurations, thereby making the system highly adaptable.
  2. Dynamic Behavior: Object Variability: Since objects are cloned from existing instances, the system can create a diverse range of objects dynamically, depending on the state of the prototype.
In summary, Creational Design Patterns offer manifold advantages in terms of adaptability and dynamic behavior. They achieve this by decoupling the client code from the specific classes that are instantiated, enabling late binding, and facilitating the plug-and-play architecture, which are seminal aspects for achieving system extensibility, modifiability, and dynamic configurability. Therefore, they are not merely patterns but strategic tools that should be astutely utilized in software architecture for building robust, dynamic, and adaptable systems.

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.

References: http://docs.oracle.com/javase/tutorial/java/javaOO/classdecl.html