Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

ReadMe.md

Abstract Factory Design Pattern is a creational design pattern in which interfaces are defined for creating families of related objects without specifying their actual implementations

Overview

The Abstract Factory pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. It's particularly useful when you need to create objects that belong to different product families but should work together.

Implementation Details

This implementation demonstrates a restaurant cuisine scenario where different factories create appropriate meal combinations:

Key Components:

  • RecipeFactory (Abstract Factory): Defines methods for creating families of related products
  • Product Families: Sandwich and Dessert abstract classes
  • Concrete Factories: AdultCuisineFactory and KidCuisineFactory
  • Concrete Products: BLT, GrilledCheese (sandwiches) and CremeBrulee, IceCreamSundae (desserts)

Classes:

  • RecipeFactory - Abstract factory defining CreateSandwich() and CreateDessert() methods
  • AdultCuisineFactory - Creates BLT sandwich and CremeBrulee dessert for adults
  • KidCuisineFactory - Creates GrilledCheese sandwich and IceCreamSundae dessert for kids
  • Sandwich - Abstract product class for sandwiches
  • Dessert - Abstract product class for desserts
  • BLT, GrilledCheese - Concrete sandwich implementations
  • CremeBrulee, IceCreamSundae - Concrete dessert implementations

Usage Example:

RecipeFactory factory;
// Based on user input, choose appropriate factory
factory = new AdultCuisineFactory(); // or KidCuisineFactory()

var sandwich = factory.CreateSandwich(); // BLT or GrilledCheese
var dessert = factory.CreateDessert();   // CremeBrulee or IceCreamSundae

Benefits:

  • Ensures that products from the same family are used together
  • Isolates concrete classes from client code
  • Makes exchanging product families easy
  • Promotes consistency among products in a family