|
9 | 9 | - Not substitutable
|
10 | 10 |
|
11 | 11 | ### S.O.L.I.D - Order doesn't matter
|
12 |
| -1. Interface segregation |
13 |
| - 1. Helps design good classes |
14 |
| - 2. Helps write unit test cases |
| 12 | +1. Interface segregation |
| 13 | + 1. Helps design good classes |
| 14 | + 2. Helps write unit test cases |
| 15 | + 3. Asks you to create a different interface for different responsibilities, in other words, don't group unrelated behavior in one interface, You break ISP if You have already an interface with many responsibilities, and the implementor doesn't need all this stuff. |
| 16 | + 4. [https://stackoverflow.com/questions/54480725/the-difference-between-liskov-substitution-principle-and-interface-segregation-p](https://stackoverflow.com/questions/54480725/the-difference-between-liskov-substitution-principle-and-interface-segregation-p) |
15 | 17 | 2. Liskov substitution - how subclasses extend superclasses
|
16 |
| - 1. Object of superclass S can be replaced with objects of any subclass of S |
17 |
| - 2. Helps design good polymorphism |
| 18 | + 1. This principle asks you to make sure that all child classes have the same behavior as the parent class. Object of superclass S can be replaced with objects of any subclass of S. |
| 19 | + 2. Helps design good polymorphism |
| 20 | + 3. Ex: Square-Rectangle Problem |
18 | 21 | 3. Open/closed - tuning the design
|
19 |
| - 1. Open to extension means adding subclasses a needed |
20 |
| - 2. Closed to modification avoids "tweaking" the code to handle new situations |
21 |
| -4. Dependency inversion - based on packaging the code |
22 |
| - 1. A direct dependency on a concrete class needs to be "inverted" |
23 |
| - 2. Depend on abstraction classes |
24 |
| - 3. Avoid concrete class name dependencies |
| 22 | + 1. Open to extension means adding subclasses a needed |
| 23 | + 2. Closed to modification avoids "tweaking" the code to handle new situations |
| 24 | + 3. A**llow its behavior to be extended without modifying its source code. Factory → we need to update the objects list only, method names are the same.** |
| 25 | +4. Dependency inversion - based on packaging the code. Decrease the dependency on another concrete class. |
| 26 | + 1. A direct dependency on a concrete class needs to be "inverted" |
| 27 | + 2. Depend on abstraction classes |
| 28 | + 3. Avoid concrete class name dependencies |
25 | 29 | 5. Single responsibility - summary of other 4 principles
|
26 |
| - 1. One responsibility per class |
27 |
| - 2. "A class should have one reason to change" |
28 |
| - 3. Note!! "Single" at what level of abstraction? How are the responsibilities counter? |
| 30 | + 1. One responsibility per class. |
| 31 | + 2. "A class should have one reason to change" |
| 32 | + 3. Note!! "Single" at what level of abstraction? How are the responsibilities counter? |
29 | 33 |
|
30 | 34 | ### Other OO Principle
|
31 | 35 | - Don't repeat yourself (DRY)
|
|
0 commit comments