Skip to content

Commit

Permalink
Corrected abstract factory pattern content to match the structure and…
Browse files Browse the repository at this point in the history
… corrected its filename.
  • Loading branch information
bytewhisperer11 committed Dec 28, 2024
1 parent c8bdc96 commit 17930cc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 108 deletions.
50 changes: 50 additions & 0 deletions Creational/AbstractFactory/abstractFactory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Abstract Factory Pattern

## Definition
The Abstract Factory Pattern is a creational design pattern that provides an interface for creating families of related or dependent objects without specifying their concrete classes. This pattern enables the client to create objects that are part of a specific group or theme, ensuring consistency among them.

## Intent
- To provide a way to encapsulate a group of factories that produce related objects.
- To ensure that families of related objects are created together without explicitly specifying their concrete classes.

## Problem
- You need to create a set of related objects, such as UI components (e.g., buttons, textboxes, dropdowns), that must be compatible with each other.
- You want to avoid hardcoding the specific classes to maintain flexibility and scalability.
- You want to support the addition of new families of products without modifying the existing code.

## Solution
- Define an abstract factory interface that declares methods for creating each product in the family.
- Implement concrete factories for each family of related products.
- Use these factories in the client code to create objects, ensuring consistency among the related products.

## Key Components
- **Abstract Factory:** Declares an interface for creating families of related objects.
- **Concrete Factory:** Implements the `Abstract Factory` interface and produces specific types of related objects.
- **Abstract Products:** Define interfaces or abstract classes for the objects to be created.
- **Concrete Products:** Implement the `Abstract Products` interfaces and represent the specific variants of the objects.
- **Client:** Uses the `Abstract Factory` to create objects without knowing their concrete classes.

## When to Use
- When your application needs to create families of related or dependent objects that must work together.
- When you want to ensure consistency among objects in a family.
- When you want to provide a way to switch between different families of related products dynamically.

## Benefits
- **Encapsulation:** Encapsulates the creation logic of related objects, keeping the client code clean and flexible.
- **Consistency:** Ensures that objects in a family are compatible with each other.
- **Scalability:** Adding new families of products is straightforward and doesn’t require changes to existing client code.
- **Decoupling:** Decouples the client code from the specific classes of the objects being created.

## When to Avoid
- When the application doesn’t involve families of related objects, as this pattern may add unnecessary complexity.
- When adding new product types to an existing family is frequent, as the pattern requires modifying all factories.

## Summary
The Abstract Factory Pattern provides a way to create families of related or dependent objects without specifying their concrete classes. It helps maintain consistency and encapsulates the creation logic, making the code more flexible and scalable.

## What to Prepare for Interview
- **Definition and Use Case:** Be ready to explain the Abstract Factory Pattern and provide examples, such as creating UI components for different platforms (e.g., Windows, macOS).
- **Code Example:** Prepare a simple code example demonstrating an abstract factory, concrete factories, and how the client interacts with them.
- **Real-World Use Cases:** Understand real-world applications like GUI libraries, database drivers, or theme-based applications.
- **Comparison with Other Patterns:** Be able to compare the Abstract Factory Pattern with patterns like Factory Method (which creates a single product) or Prototype (which creates objects by cloning).
- **Benefits and Trade-offs:** Discuss the advantages and limitations, such as consistency among product families versus the complexity of adding new product types.
108 changes: 0 additions & 108 deletions Creational/AbstractFactory/abstractFactoryNew.md

This file was deleted.

0 comments on commit 17930cc

Please sign in to comment.