Diamond inheritance (C++)

前端 未结 7 1040
时光取名叫无心
时光取名叫无心 2020-11-29 04:04

I know that having diamond inheritance is considered bad practice. However, I have 2 cases in which I feel that diamond inheritance could fit very nicely. I want to ask, wou

7条回答
  •  情书的邮戳
    2020-11-29 04:53

    For case 2, isn't a OneCommand just a special case of CompositeCommand? If you eliminate OneCommand and allow CompositeCommands to only have one element, I think your design gets simpler:

                  CommandAbstraction
                     /          \
                    /            \
                   /              \
            ModernCommand      CompositeCommand
                   \               /
                    \             /
                     \           /
                 ModernCompositeCommand
    

    You still have the dreaded diamond, but I think this may be an acceptable case for it.

提交回复
热议问题