java traits or mixins pattern?

joshjdevl picture joshjdevl · Nov 4, 2008 · Viewed 16.8k times · Source

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

Answer

sblundy picture sblundy · Nov 4, 2008

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 lack of multiple inheritance in java.