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

Summary

We had a pretty detailed look at Java interfaces and got to know that interfaces are contracts. When a class implements the contract, we can reuse the existing code. The iterator pattern is an example of such a contract. By following the interface iterable's contract, we were able to reuse the Java code for each loop with our own custom class.

When a language supports multiple inheritances, the method resolution might get ambiguous. Java does not support multiple inheritance, hence, we don't see this problem.

Scala traits resolve many of these problems. We can put in reusable code in traits and then mix-in traits into our classes or objects as needed. We looked at how mix-ins enable rich interfaces. Traits are stackable and allow us to change ...

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