An interface Worker has work(), eat() and sleep(). A Robot must implement eat() with raise NotImplementedError. Which principle suggests a fix?
Options
- Interface Segregation (Correct option)
- Open/Closed
- DRY
- Law of Demeter
Answer
Interface Segregation
Why
Interface Segregation says: do not force a class to depend on methods it does not use.
One big interface makes Robot fake an eat() method. Split it into small interfaces (Workable, Eatable) and let each class implement only what applies to it.
Remember
Many small interfaces beat one big one.