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 |
+------------------+ +------------------+
Top comments (0)