Bonaventure Systems's Zoom Meeting 5_24_2025, 8_03_08 AM_selection-[1748070334530].png

Bonaventure Systems's Zoom Meeting 5_24_2025, 8_03_08 AM_Page 1-[1748072152232].png

SOLID Principles with Real-World Examples

Code 1: Factory Pattern with Template Method (_02DemoOOP)

This demonstrates the Factory Pattern combined with the Template Method Pattern.

Class Hierarchy

Report (Abstract Base Class)
├── PDF
├── DOCX
├── TEXT
└── SpecialReport (Abstract)
    └── PPTX

Key Components Analysis

1. Abstract Base Class - Report

public abstract class Report
{
    protected abstract void Create();
    protected abstract void Parse();
    protected abstract void Validate();
    protected abstract void Save();

    public virtual void GenerateReport()  // Template Method
    {
        Create();
        Parse();
        Validate();
        Save();
    }
}

Purpose: Defines the common structure and workflow for all reports.

2. Intermediate Abstract Class - SpecialReport

public abstract class SpecialReport : Report
{
    protected abstract void ReValidate();

    public override void GenerateReport()  // Modified workflow
    {
        Create();
        Parse();
        Validate();
        ReValidate();  // Additional step
        Save();
    }
}

Purpose: Extends the base workflow with additional validation step.

3. Concrete Implementations

Each concrete class implements the abstract methods:

public class PDF : Report
{
    protected override void Create() { Console.WriteLine("PDF Created"); }
    protected override void Parse() { Console.WriteLine("PDF Parsed"); }
    protected override void Validate() { Console.WriteLine("PDF Validated"); }
    protected override void Save() { Console.WriteLine("PDF Saved"); }
}