Interface Segregation Principle

The Interface Segregation Principle (ISP) suggests that a class should not be forced to implement methods it doesn’t need.

Bad Practice - Principle not followed


            +------------------+
            |   <<interface>>  |
            |     IVehicle     |
            +------------------+
            | + drive()        |
            | + fly()          |
            +------------------+    
                ^         ^
                |         |               
+------------------+    +------------------+
|      Car         |    |    Airplane      |
+------------------+    +------------------+
| + drive()        |    | + drive()        |
| + fly()          |    | + fly()          |
+------------------+    +------------------+

Good Practice - Principle followed



+------------------+              +------------------+
|   <<interface>>  |              | <<interface>>    |
|      ICar        |              |    IAirplane     |
+------------------+              +------------------+
| + drive()        |              | + fly()          |
+------------------+              +------------------+
        ^                                ^
        |                                |
+------------------+              +------------------+
|      Car         |              |    Airplane      |
+------------------+              +------------------+
| + drive()        |              | + fly()          |
+------------------+              +------------------+
| <<implements>>   |              | <<implements>>   |
|      ICar        |              |    IAirplane     |
+------------------+              +------------------+
0
Subscribe to my newsletter

Read articles from Palanivel SundaraRajan GugaGuruNathan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Palanivel SundaraRajan GugaGuruNathan
Palanivel SundaraRajan GugaGuruNathan

Hi , thanks for stopping by! I am full-stack developer and I'm passionate about making complex concepts clear through code and visuals. After all, a picture (and a code snippet) is worth a thousand words! I hope you enjoy my blog.