O'Reilly logo

Programming Groovy 2 by Venkat Subramaniam

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

Decorating Classes with Multiple Mixins

When we mix in multiple classes, all of those classes’ methods are available in the target class. By default, methods hide on collision. That is, if two or more classes being mixed in have methods with the same name and parameters’ signature, the method in the latest-added mixin hides the method that has already been injected.

We can program these methods to instead collaborate in a way that the call can result in a chain of methods calls. Let’s create a chain of filters to transform the parameters they receive; we’ll see how mixins can provide such a design option.

An application needs different types of writers; the target may be a file, a socket, a web service, a simple string, and so on. We’ve generalized ...

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