Skip to content

Codem-3/CreationalPatterns-FactoryPattern

Repository files navigation

Creational Patterns - Factory Pattern

Overview

The Factory Pattern is another essential design pattern within the creational patterns group, which focuses on object-creation mechanisms. The primary purpose of the Factory Pattern is to define an interface for creating an object, but let subclasses alter the type of objects that will be created. It provides a way to delegate the instantiation logic to child classes.

Why Use Factory Pattern?

  1. Decoupling Object Creation: Separates the code that specifies how objects are created from the code that uses the objects.
  2. Flexibility: Makes it easier to introduce new types of products without changing the existing code.
  3. Enhancing Code Maintainability: Centralizes the object creation process, making it easier to manage and maintain.

Benefits of Factory Pattern

  1. Encapsulation: Encapsulates the object creation code, making it easier to manage.
  2. Scalability: Facilitates the addition of new products without modifying existing code.
  3. Single Responsibility Principle: Adheres to the single responsibility principle by separating object creation from object usage.

Drawbacks of Factory Pattern

  1. Complexity: Introduces additional complexity with factory classes.
  2. Overhead: Can add overhead by creating numerous small factory classes or methods.
  3. Abstraction Misuse: Potential misuse of abstraction if not implemented correctly, leading to less readable code.

About

Implementation on Creational Patterns - Factory Pattern

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages