你见过用保护内部访问修饰符的合理使用设计? [英] Have you ever seen design with reasonable usage of protected internal access modifier?

查看:126
本文介绍了你见过用保护内部访问修饰符的合理使用设计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有,但我不说没有一个。

I haven't, but I don't say there isn't one.

所有谁读这大概知道什么是内部保护的C#开发人员并且当使用它。我的问题很简单:你真的永远使用它,或者使用受保护的内部访问修饰符一个成功的设计项目的工作?如果是,请分享你的知识和后漂亮的样品,在那里我终于可以欣赏这个棘手的改性剂使用巧妙

All of the C# developers who read this probably do know what is protected internal and when to use it. My question is simple : did you actually ever use it or worked on a successfully designed project using protected internal access modifier? If yes, please share your knowledge and post nice sample, where I can finally appreciate clever usage of this tricky modifier.

//我相信这不是主观的,我我其实寻找一个答案; - )

// I believe this isn't subjective, I am actually seeking for an answer ;-)

推荐答案

我相信你能想到的例子,但在五年内的C#发展,我从来没见过它一个很好的案例。约翰·K公司的例子说明了用途的修饰符的很好,但是我认为,导致这种局面的要求是有问题的。在约翰·K公司的例子中,类有组件中的友好访问,一般这是麻烦,因为这些类很可能是问,而不是告诉(编程是不礼貌的,这是更好地告诉比问)。在什么情况下,你有一个有用的扩展类的朋友可以致电上,但其他人不能的方法?

I'm sure you can think of examples, but in five years of C# development, I've not seen a good case for it. John K's example illustrates the intended use of the modifier nicely, however I think the requirements that lead to this situation are problematic. In John K's example, the class has "friendly" access within the assembly, and in general this is trouble, because those classes are probably "asking", not "telling" (programming is not polite, it is better to tell than to ask). In what case do you have a useful extendable class that Friends can call a method on but others cannot?

另一个用途是用于测试接入(例如,你希望它被保护,但内部让你的装配水平测试可以调用它)。这是一个麻烦的情况太 - 当你暴露事物的内部测试,我认为它是一个设计的气味是依赖注入通常可以处理。

Another use would be for testing access (IE you want it to be protected, but internal so your assembly level tests can call it). This is a trouble situation too - when you expose things as internal for testing I think it is a design smell that dependency injection can usually handle.

这篇关于你见过用保护内部访问修饰符的合理使用设计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆