Skip to content

anfeespi/DesignPatterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Design Patterns Pizza Application

Overview

This Spring Boot application demonstrates 9 essential design patterns using a pizzeria theme. Each pattern is implemented in its own package and i tried to do examples in almost all (i promise i will update). I do it with pizza because it's one of my favorites foods in the world :D

Patterns Included

1. Singleton Pattern (dev.anfeespi.designpatterns.singleton)

  • What: Ensures only one instance of a class exists
  • Example: PizzaOven - only one oven should exist in the pizzeria

2. Factory Pattern (dev.anfeespi.designpatterns.factory)

  • What: Creates objects without specifying exact classes
  • Example: PizzaFactory creates different types of pizzas
  • Pizza Types: margherita, pepperoni, veggie

3. Abstract Factory Pattern (dev.anfeespi.designpatterns.abstractfactory)

  • What: Creates families of related objects
  • Example: Different ingredient factories for Italian vs American style
  • Styles: italian, american

4. Builder Pattern (dev.anfeespi.designpatterns.builder)

  • What: Constructs complex objects step by step
  • Example: Building a complex pizza order with multiple options

5. Decorator Pattern (dev.anfeespi.designpatterns.decorator)

  • What: Adds features to objects dynamically
  • Example: Adding toppings to pizzas without changing the base class

6. Observer Pattern (dev.anfeespi.designpatterns.observer)

  • What: Notifies multiple objects about state changes
  • Example: Order tracking system notifying customers, kitchen, delivery

7. Strategy Pattern (dev.anfeespi.designpatterns.strategy)

  • What: Defines interchangeable algorithms
  • Example: Different cooking methods (oven, wood-fired, convection)
  • Methods: oven, woodfired, convection

8. Facade Pattern (dev.anfeespi.designpatterns.facade)

  • What: Provides simplified interface to complex subsystem
  • Example: Simple pizza ordering process hiding internal complexity

9. Adapter Pattern (com.pizzeria.designpatterns.adapter)

  • What: Allows incompatible interfaces to work together
  • Example: Integrating third-party payment system with our interface

Project Structure

src/main/java/dev/anfeespi/designpatterns/
├── DesignPatternsApplication.java          # Main class
├── singleton/
│   └── PizzaOven.java                      # Singleton pattern
├── factory/
│   ├── pizza/
│   │   ├── Pizza.java                          
│   │   ├── MargheritaPizza.java               
│   │   ├── PepperoniPizza.java
│   │   └── VeggiePizza.java
│   └── PizzaFactory.java                   # Factory
├── abstract_factory/
│   ├── base_products/
│   │   ├── Dough.java
│   │   ├── Sauce.java
│   │   └── Cheese.java
│   ├── products/                           # Concrete products
│   ├── IngredientFactory.java              # Abstract factory
│   ├── ItalianIngredientFactory.java      
│   └── AmericanIngredientFactory.java
├── builder/
│   └── PizzaOrder.java                     # Builder pattern
├── decorator/
│   ├── PizzaComponent.java                 # Component interface
│   ├── BasicPizza.java                     # Concrete component
│   ├── ToppingDecorator.java               # Base decorator
│   ├── CheeseDecorator.java
│   ├── MushroomDecorator.java
│   └── PepperoniDecorator.java             # Concrete decorators
├── observer/
│   ├── OrderObserver.java                  # Observer interface
│   ├── OrderTracker.java                   # Subject
│   ├── DeliveryTracker.java
│   ├── KitchenDisplay.java
│   └── CustomerNotifier.java               # Concrete observers
├── strategy/
│   ├── CookingStrategy.java                # Strategy interface
│   ├── *Cooking.java                       # Concrete strategies
│   └── PizzaChef.java                      # Context class
├── facade/
│   └── PizzaOrderingFacade.java            # Facade pattern
└── adapter/
    ├── PaymentProcessor.java               # Target interface
    ├── ThirdParty.java                     # The third party or class unmodifiable
    ├── PaymentAdapter.java                 #Adapter
    └── PizzaPaymentService.java            # Example (more or less)

src/main/resources/
└── application.properties                  # Configuration

Key Points

Singleton Pattern

  • Thread-safe implementation using synchronized keyword
  • Private constructor prevents external instantiation
  • Shared state across all references

Factory Pattern

  • Centralizes object creation logic
  • Easy to extend with new pizza types
  • Follows Open/Closed Principle

Abstract Factory Pattern

  • Creates families of related objects
  • Easy to switch between different product families
  • Ensures compatibility between related products

Builder Pattern

  • Handles complex object construction
  • Fluent interface for readability
  • Validation in build() method

Decorator Pattern

  • Dynamic feature addition without inheritance
  • Follows Single Responsibility Principle
  • Flexible combination of features

Observer Pattern

  • Loose coupling between subject and observers
  • Dynamic subscription/unsubscription
  • Broadcast communication pattern

Strategy Pattern

  • Runtime algorithm selection
  • Easy to add new strategies
  • Eliminates conditional statements

Facade Pattern

  • Simplifies complex subsystem interactions
  • Provides unified interface
  • Hides implementation details

Adapter Pattern

  • Integrates incompatible interfaces
  • Reuses existing functionality
  • Bridge between different systems

🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages