Language: English O’zbek

SOLID Principles in Python

SOLID Principles in Python

SOLID is an acronym for five design principles introduced by Robert C. Martin (Uncle Bob). They guide developers toward code that is maintainable, flexible, and easy to extend.

Each principle is demonstrated with a violation (what goes wrong) and a correct implementation (how to fix it), accompanied by a UML class diagram.

Principles

# Principle Description
S Single Responsibility (SRP) A class should have only one reason to change
O Open/Closed (OCP) Open for extension, closed for modification
L Liskov Substitution (LSP) Subtypes must be substitutable for their base types
I Interface Segregation (ISP) Clients should not depend on interfaces they don’t use
D Dependency Inversion (DIP) Depend on abstractions, not concrete implementations

Running the Examples

Each file is a standalone script. Run any example directly:

python docs/01-srp/violation.py
python docs/01-srp/correct.py

Requirements: Python 3.10+, no external dependencies.

License

MIT — Yakhyokhuja Valikhujaev