Skip to content

Design Patterns Demo 1

GabrielaBerimbau edited this page Jul 27, 2026 · 1 revision

Design Patterns

Mealchemy uses selected object-oriented design patterns to improve modularity, maintainability, extensibility, and separation of concerns across the frontend, backend, and recommendation systems.

The proposed participants and implementations described below are based on the current system design and domain model and may evolve as implementation progresses.


Strategy Pattern

Purpose

The Strategy Pattern is used when multiple interchangeable algorithms or processing approaches are required for the same operation.

Mealchemy Participants

  • Context: RecommendationEngine
  • Strategy Interface: RecommendationStrategy
  • Concrete Strategies:
    • PantryBasedRecommendationStrategy
    • PreferenceBasedRecommendationStrategy
    • NutritionBasedRecommendationStrategy
    • DiscoveryHistoryRecommendationStrategy
  • Supporting Domain Classes:
    • PantryIngredients
    • UserPreferences
    • Recipe
    • DiscoverySwipe
    • NutritionalInfo

Use in Mealchemy

Mealchemy generates recipe recommendations using several forms of user context, including pantry contents, dietary restrictions, nutritional goals, flavour preferences, and discovery history.

The domain model includes classes such as PantryIngredients, UserPreferences, Recipe, DiscoverySwipe, and NutritionalInfo, all of which contribute to recommendation generation.

Using the Strategy Pattern allows the recommendation engine to switch between or combine different recommendation algorithms without changing the rest of the system.


Factory Method Pattern

Purpose

The Factory Method Pattern is used to create specialised object types while centralising object creation logic.

Mealchemy Participants

  • Creator: VaultFactory
  • ConcreteCreator: Vault
  • Concrete Products:
    • Private
    • Shared
    • Global

Use in Mealchemy

The domain model shows Vault specialised into Private, Shared, and Global vault types.

Instead of manually creating vault objects throughout the codebase, a VaultFactory can determine and instantiate the correct vault type based on user actions or system requirements.

This improves maintainability and allows additional vault types to be introduced later without modifying the client code responsible for vault creation.

The same pattern may also be applied to user role creation, where users may be instantiated as Admin or General User.


Observer Pattern

Purpose

The Observer Pattern is used when changes in one part of the system should automatically notify or trigger updates in dependent components.

Mealchemy Participants

  • Subject: PantryIngredients
  • Observers:
    • ShoppingList
    • RecommendationEngine
    • DiscoverySession
  • Related Domain Classes:
    • ShoppingListItem
    • Recipe
    • DiscoverySwipe

Use in Mealchemy

Changes to pantry ingredients affect multiple areas of the system. For example:

  • ingredient availability may affect recipe recommendations,
  • shopping list generation may need updating,
  • discovery recommendations may change based on available ingredients.

The domain model shows relationships between pantry management, recipes, shopping lists, and discovery systems.

Using the Observer Pattern allows dependent systems to react to pantry updates without tightly coupling all components directly together.


Adapter Pattern

Purpose

The Adapter Pattern is used to integrate external systems while isolating the rest of the application from external API structures or protocol differences.

Mealchemy Participants

  • Target Interface: Internal recommendation and nutrition service interfaces
  • Adapters:
    • AIRecommendationAdapter
    • NutritionDataAdapter
    • ShoppingPricingAdapter
  • Adaptees: External recommendation, nutrition, and pricing services

Use in Mealchemy

Mealchemy integrates with external systems for recommendation support, nutritional analysis, and shopping or pricing information.

Each external service may expose different request formats, authentication methods, or response structures. Adapter classes convert external responses into a consistent internal format used by Mealchemy services.

This reduces coupling between the application and third-party systems and simplifies future API replacement or modification.


Template Method Pattern

Purpose

The Template Method Pattern is used when multiple workflows follow the same high-level process but differ in specific implementation steps.

Mealchemy Participants

  • Abstract Template Class: RecipeProcessor
  • Concrete Implementations:
    • ManualRecipeProcessor
    • GeneratedRecipeProcessor
    • SharedVaultRecipeProcessor
  • Related Domain Classes:
    • Recipe
    • RecipeIngredient
    • RecipeStep
    • Vault

Use in Mealchemy

Recipes may originate from different sources, including manually uploaded recipes, generated recipes, or recipes stored in shared vaults.

Despite different sources, recipe processing generally follows the same sequence:

  1. Validate recipe data
  2. Process ingredients
  3. Process recipe steps
  4. Generate nutritional information
  5. Store the recipe
  6. Add the recipe to a vault

The Template Method Pattern allows the shared processing structure to remain consistent while allowing source-specific processing behaviour to vary between implementations.

Mealchemy

Team PUL5E · COS 301


Documentation

Demo 4
Demo 3
Demo 2
Demo 1

Setup Guides


Quick Links


Updated: 13 September 2026

Clone this wiki locally