Design pattern to use instead of multiple inheritance

后端 未结 8 2524
离开以前
离开以前 2020-12-09 03:16

Coming from a C++ background, Im used to multiple inheritance. I like the feeling of a shotgun squarely aimed at my foot. Nowadays, I work more in C# and Java, where you can

8条回答
  •  既然无缘
    2020-12-09 03:40

    Replace inheritance with composition.

    Move your 'common' function to separate class, create an instance of that class, and insert it to TypeA object and to TypeB object.

提交回复
热议问题