Design pattern to use instead of multiple inheritance

后端 未结 8 2526
离开以前
离开以前 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:47

    Your gut is correct in this case. The Adapter pattern is what you're looking for.

    DoFactory has good .NET examples (that should be pretty close to their Java counterparts as well):

    Adapter Design Pattern in C# and VB.NET

    0 讨论(0)
  • 2020-12-09 03:47
    abstract class Magical: CustomButtonUserControl
    {
        public void DoMagic()
        {
            // ...
        }
    }
    
    public class TypeA : Magical
    {
    
    }
    
    public class TypeB : Magical
    {
    
    }
    
    0 讨论(0)
提交回复
热议问题