You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here we are going to take an example on a `AudioPlayer`, `VideoPlayer` and `MediaPlayer` interface.
5
+
6
+
### Bad point of view
7
+
In the bad ISP example, we have a `MediaPlayer` interface that has methods for both audio and video. This is a violation of the ISP because the `AudioPlayer` and `VideoPlayer` classes are forced to implement methods that they don't need.
8
+
9
+
### Good point of view
10
+
In the good ISP example, we have a `AudioPlayer` interface and a `VideoPlayer` interface. This is a better design because the `AudioPlayer` and `VideoPlayer` classes are only forced to implement the methods that they need.
Copy file name to clipboardExpand all lines: 04-SOLID/README.md
+11-5
Original file line number
Diff line number
Diff line change
@@ -12,23 +12,29 @@ Principle SOLID 5 software design principles that help to create a good software
12
12
- Interface Segregation Principle
13
13
- Dependency Inversion Principle
14
14
15
-
###Single Responsibility Principle (SRP)
15
+
## Single Responsibility Principle (SRP)
16
16
***A class should have only one reason to change***\
17
17
We determine responsability of one class according to the **social structure** of the **users usage**. \
18
18
**Example:** go to file [SingleResponsibilityPrinciple](./04x01_SRP)
19
19
20
-
###Open-Closed Principle (OCP)
20
+
## Open-Closed Principle (OCP)
21
21
***A class should be open for extension, but closed for modification***\
22
22
This principle is about **extending** the behavior of a class without **modifying** it. So to add new functionality, it shouldn't require changing the existing code.
23
23
24
24
**Tips**: To do this, we write **interfaces** and **abstract classes** in order to dictate the higher-level policy that needs to be implemented, and then we implement that policy using concrete classes.
25
25
26
26
**Example:** go to file [OpenClosedPrinciple](./04x02_OCP)
27
27
28
-
###LisKov-Substitution Principle (LSP)
28
+
## LisKov-Substitution Principle (LSP)
29
29
***Derived classes must be substitutable for their base classes***
30
30
31
-
32
31
This principle is about **inheritance** and **polymorphism**. It states that if a program is using a base class, then the reference to the base class can be replaced with a derived class without affecting the functionality of the program.
33
32
34
-
**Example:** go to file [LiskovSubstitutionPrinciple](./04x03_LSP)
33
+
**Example:** go to file [LiskovSubstitutionPrinciple](./04x03_LSP)
34
+
35
+
## Interface Segregation Principle (ISP)
36
+
***A client should never be forced to implement an interface that it doesn't use***
37
+
38
+
This principle is about **interfaces**. It states it’s better to have `smaller`, `focused`**interfaces** rather than large, monolithic ones.
39
+
40
+
**Example:** go to files[InterfaceSegregationPrinciple](./04x04_ISP)
0 commit comments