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.
The project is organized into self-contained scripts for each problem:
-
Liskov Substitution Principle (LSP) -
problem1_lsp.py- Scenario: Shape hierarchy.
- Demonstration: Shows how a
Squareinheriting fromRectanglecan violate LSP, and provides a corrected hierarchy using a commonShapeabstraction.
-
Interface Segregation Principle (ISP) -
problem2_isp.py- Scenario: Worker interfaces for Humans and Robots.
- Demonstration: Refactors a bloated
Workerinterface into granular interfaces (Workable,Eatable, etc.) so classes likeRobotaren't forced to implement methods they don't use.
-
Dependency Inversion Principle (DIP) -
problem3_dip.py- Scenario: Notification system.
- Demonstration: Decouples
NotificationManagerfrom concrete implementations (Email/SMS) by introducing aNotificationServiceabstraction.
-
Strategy Pattern -
problem4_strategy.py- Scenario: Payment processing.
- Demonstration: Encapsulates payment algorithms (Credit Card, PayPal) into interchangeable strategy classes, allowing runtime switching.
-
Observer Pattern -
problem5_observer.py- Scenario: News publisher and subscribers.
- Demonstration: Implements a localized Pub/Sub mechanism where
NewsPublishernotifies various subscribers (Email, SMS) about updates without tight coupling.
-
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).
-
Adapter Pattern -
problem7_adapter.py- Scenario: Third-party payment service integration.
- Demonstration: Wraps an incompatible
LegacyPaymentServicewith an adapter to make it work with the standardPaymentProcessorinterface.
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- Python 3.x
- No external dependencies required (uses standard library).