SOLID ਪੰਜ ਆਬਜੈਕਟ-ਓਰੀਐਂਟਿਡ ਡਿਜ਼ਾਈਨ ਸਿਧਾਂਤਾਂ ਦਾ ਇੱਕ ਸਮੂਹ ਹੈ ਜੋ ਬਣਾਈ ਰੱਖਣ ਯੋਗ, ਲਚਕਦਾਰ, ਸਮਝ ਵਿੱਚ ਆਣ ਵਾਲਾ ਕੋਡ ਪ੍ਰਚਾਰ ਕਰਦਾ ਹੈ: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, ਅਤੇ Dependency Inversion। ਇਹ ਚੰਗੇ OO ਡਿਜ਼ਾਈਨ ਦੀ ਸੰਚਾਲਨ ਕਰਦੇ ਹਨ।
ਪੰਜ ਸਿਧਾਂਤ
S — SINGLE RESPONSIBILITY → a class should have ONE reason to change (one responsibility/job)
→ don't make classes do too much (avoid God objects)
O — OPEN/CLOSED → open for EXTENSION, closed for MODIFICATION → add new behavior without
changing existing code (e.g. via polymorphism/strategies)
L — LISKOV SUBSTITUTION → subtypes must be substitutable for their base types (a subclass
shouldn't break behavior expected of the parent)
I — INTERFACE SEGREGATION → many specific interfaces > one fat interface → clients shouldn't
depend on methods they don't use
D — DEPENDENCY INVERSION → depend on ABSTRACTIONS, not concrete implementations → high-level
modules don't depend on low-level details (relates to DI)
