Answer by user3478180 for java traits or mixins pattern?
As of Java-8, default interface methods were added. This, together with multiple inheritance of interfaces in Java should allow some sort of mixin. Clearly the interfaces have to operate independently....
View ArticleAnswer by Henno Vermeulen for java traits or mixins pattern?
You can exploit the fact that interfaces allow nested classes (automatically public static) to keep the default implementation of the interface methods encapsulated within the interface itself. I.e....
View ArticleAnswer by x_rex for java traits or mixins pattern?
Implementing simple mixin/traits support in java using CGLib/javassit is quite easy. You can take a look for instance here for small example. More complete, ready to use solution might be found: here
View ArticleAnswer by Pablo La Greca for java traits or mixins pattern?
QI4J allows you to use mixins
View ArticleAnswer by Chris Vest for java traits or mixins pattern?
Is the object-purist stirring in you today? Think you could do with a little composite oriented programming? Then you, sir, are looking for Apache Polygene (formerly Qi4J or Zest) ;)
View ArticleAnswer by Alex B for java traits or mixins pattern?
I would encapsulate all of the business logic into a new class BusinessLogic and have each class that needs BusinessLogic make calls to the class. If you need a single rooted heirarchy for your classes...
View ArticleAnswer by sblundy for java traits or mixins pattern?
Not the way you want to do it. Effective Java recommends that you "Favor composition over inheritance". Meaning you move the common logic to other classes and delegate. This is how you get around the...
View ArticleAnswer by David Koelle for java traits or mixins pattern?
Java's answer to multiple inheritance is the ability to implement multiple interfaces. Of course, this means you'll get the method declarations, but not the logic. You could try emulating mixins by...
View Articlejava traits or mixins pattern?
Is there a way to emulate mixins or traits in java? basically, I need a way to do multiple inheritance so I can add common business logic to several classes
View Article