Skip to content

khadijafatima409/oop-solid-design-patterns

Repository files navigation

Assignment 3: SOLID Principles & Design Patterns

Overview

This repository contains solutions for Module 3 - Advanced Design Problem Solving. It demonstrates key SOLID principles and Design Patterns through practical Python implementations. Each problem addresses a specific scenario to showcase the benefits of adherence to these architectural concepts.

Structure

The project is organized into self-contained scripts for each problem:

  1. Liskov Substitution Principle (LSP) - problem1_lsp.py

    • Scenario: Shape hierarchy.
    • Demonstration: Shows how a Square inheriting from Rectangle can violate LSP, and provides a corrected hierarchy using a common Shape abstraction.
  2. Interface Segregation Principle (ISP) - problem2_isp.py

    • Scenario: Worker interfaces for Humans and Robots.
    • Demonstration: Refactors a bloated Worker interface into granular interfaces (Workable, Eatable, etc.) so classes like Robot aren't forced to implement methods they don't use.
  3. Dependency Inversion Principle (DIP) - problem3_dip.py

    • Scenario: Notification system.
    • Demonstration: Decouples NotificationManager from concrete implementations (Email/SMS) by introducing a NotificationService abstraction.
  4. Strategy Pattern - problem4_strategy.py

    • Scenario: Payment processing.
    • Demonstration: Encapsulates payment algorithms (Credit Card, PayPal) into interchangeable strategy classes, allowing runtime switching.
  5. Observer Pattern - problem5_observer.py

    • Scenario: News publisher and subscribers.
    • Demonstration: Implements a localized Pub/Sub mechanism where NewsPublisher notifies various subscribers (Email, SMS) about updates without tight coupling.
  6. Repository Pattern - problem6_repository.py

    • Scenario: User data management.
    • Demonstration: Abstract data access behind a UserRepository, separating business logic from storage details (In-Memory implementation provided).
  7. Adapter Pattern - problem7_adapter.py

    • Scenario: Third-party payment service integration.
    • Demonstration: Wraps an incompatible LegacyPaymentService with an adapter to make it work with the standard PaymentProcessor interface.

How to Run

Each file is a standalone Python script that includes a if __name__ == "__main__": block demonstrating the pattern in action.

You can run any problem using python:

python problem1_lsp.py
python problem2_isp.py
# ... and so on

Requirements

  • Python 3.x
  • No external dependencies required (uses standard library).

About

A collection of Python scripts demonstrating SOLID principles and Design Patterns (LSP, ISP, DIP, Strategy, Observer, Repository, Adapter) through practical examples and problem-solving scenarios for Module 3 assignment.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages