Repaso
Español
Design & PracticesIntermediateDP-04

An interface Worker has work(), eat() and sleep(). A Robot must implement eat() with raise NotImplementedError. Which principle suggests a fix?

Options

  1. Interface Segregation (Correct option)
  2. Open/Closed
  3. DRY
  4. 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.

Key terms

Practice this question in Repaso