有没有任何有效的理由不使用公共虚拟方法? [英] Is there any valid reason for not using public virtual methods?
本文介绍了有没有任何有效的理由不使用公共虚拟方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有任何有效的理由不使用公共虚拟方法?
我在某处阅读了我们应该避免使用公共虚拟方法,但我想从专家确认如果这是有效的语句?
解决方案
对于良好稳定的API设计,非虚拟接口是一个很好的习惯。 / p>
我要遵循现有的有关这方面的优秀文献:
另请参阅以下精采答案:
(Sumant Tambe有一个引人入胜的矩阵设计意图的影响在他的博客,有更多的位设计意图。)
Is there any valid reason for not using public virtual methods?
I have read somewhere that we should avoid using public virtual methods, but I want to confirm from experts if this is valid statement?
解决方案
For good and stable API design, the Non-Virtual-Interface is a good idiom.
I'm going to defer to the existing good literature on this:
See also these splendid answers:
- What is the point of a private pure virtual function?
- Call a C++ base class method automatically
- Best way to declare an interface in C++11
- How to ensure that virtual method calls get propagated all the way to the base class?
- What's the advantage of this indirect function call?
(Sumant Tambe has an intriguing matrix of Design Intent Implications on his blog, which has a few more bits on design intent.)
这篇关于有没有任何有效的理由不使用公共虚拟方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文