The document discusses the SOLID principles of object-oriented design, which are Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion. It defines each principle, provides examples of how to apply it in code, and explains how following the principles can help create code that is loosely coupled, highly cohesive, reusable, and easily testable.
27. • Loosely Coupled - Dependency Injection
Why SOLID?
It helps us to write code which is
28. • Loosely Coupled - Dependency Injection
• Highly Cohesive - Single Responsibility
Why SOLID?
It helps us to write code which is
29. • Loosely Coupled - Dependency Injection
• Highly Cohesive - Single Responsibility
• Easily Composable - Can be changed
Why SOLID?
It helps us to write code which is
30. • Loosely Coupled - Dependency Injection
• Highly Cohesive - Single Responsibility
• Easily Composable - Can be changed
• Context Independent - Can be
rearranged
Why SOLID?
It helps us to write code which is
31. • Loosely Coupled - Dependency Injection
• Highly Cohesive - Single Responsibility
• Easily Composable - Can be changed
• Context Independent - Can be
rearranged
• Reusable
Why SOLID?
It helps us to write code which is
32. • Loosely Coupled - Dependency Injection
• Highly Cohesive - Single Responsibility
• Easily Composable - Can be changed
• Context Independent - Can be rearranged
• Reusable
• Easily testable code
Why SOLID?
It helps us to write code which is
52. Subclasses should be
substitutable for their base
classes.
Liskov Substitution
Let q(x) be a property provable about objects x of type T.
Then q(y) should be true for objects y of type S where S is
subtype of T
53. If a piece of client code works for a
type then it must work for all derived
types.
A new subtype should not screw up
the client code.
Liskov Substitution
54. • Implement inheritance based on
behaviour.
• Obey the pre and postconditions rules.
Liskov Substitution
Rules
63. Depend on abstractions.
Do not depend on concretions.
Dependency Inversion
A. High-level modules should not depend on low-level modules. Both should
depend on abstractions.
B. Abstractions should not depend on details. Details should depend on
abstractions.