O'Reilly logo

Learning Scala Programming by Vikash Sharma

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

Traits as composable mix-ins

By composable mix-ins we mean that we can create an instance of a particular type, with mix-ins of a trait, that can have certain additive functionalities. If you're thinking why would we want to do that, then the answer is maybe you want to add some particular behavior that makes sense to your functionality and you want it to behave as if it has come from the library itself. As a client of such constructs or libraries, we want them to feel as natural as they are. Traits help us add certain functions, keeping the real library intact.

We can understand this better with the help of an example. So, suppose you have an already existing CreditCard functionality. For demonstration purposes, we'll limit our expectations ...

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