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 the existing object methods, namely stackable modifications.
Dependencies injection is a very popular pattern. The general theme behind it is inversion of control. Scala traits allow us to come up with their own dependencies injection and the cake...