Interfaces as types
Interfaces specify only what a class can do (or which contracts it obeys) and not how the class does this. On the other hand, non-related classes can share some common behavior. If we somehow could write this behavior in one place, we would be following the Don't Repeat Yourself principle (DRY).
Note
The DRY principle aims at reducing repetition. We can look at a method, a function, or a class as a piece of knowledge. This means that a function or method knows how to do something. The principle tells us not to duplicate this know-how.
It is easier to change this one piece or replace it with another, as this won't affect other logically unrelated elements. Brian Kernighan, the legendary programmer, calls this the Single Point Of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access