java traits or mixins pattern?

前端 未结 8 2197
小蘑菇
小蘑菇 2020-12-16 14:02

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

8条回答
  •  情歌与酒
    2020-12-16 14:18

    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.

提交回复
热议问题