本文介绍了有什么设计模式可以解决仅向某些类公开几种方法的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我知道朋友的概念在OOP设计中是不可以的.
但是,有时在某些情况下,只有在类之间相互缠绕在一起的情况下,才允许某些朋友类访问某个类的某些方法.

例如,CGridCtrl的朋友类是CGridCellBase.要了解我在说哪个示例,请查看Chris Maunder撰写的与代码项目中CGridCtrl相关的文章.

因此,如果我要用不支持friend关键字的语言开发类似的东西,我如何确定CGridCtrl的某些方法只能由CGridCellBase类访问?解决方案




Hi,

I know friend concept is a no no in OOP design.
But, sometimes there are cases where you''d allow access of certain methods of a class by certain friend classes only given the classes are very inter-twined to each other.

For example, CGridCtrl''s friend class is CGridCellBase. To understand, which example I am talking about, please have a look at the article by Chris Maunder related to CGridCtrl in code project.

So, if I were to develop something similar in a language which doesn''t support the friend keyword, how would I make sure, CGridCtrl''s certain methods are only accessible by CGridCellBase class only?

解决方案




这篇关于有什么设计模式可以解决仅向某些类公开几种方法的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 05:22