O'Reilly logo

Scala Functional Programming Patterns by Atul S. Khot

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required