按合同设计可以让我强制执行私有方法吗
我无法用语言做到这一点 如何强制执行私有方法,因为接口方法只是公开?
那么我可以使用合同设计吗?
I can't do this with language
How to enforce private method since interface methods are only public?
so can I use design by contract instead ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有兴趣实施特定的编码风格、命名约定或类似的事情,您最好为 FxCop 或 StyleCop。C# 语言或 .NET 环境中确实没有任何功能可以帮助您执行此类操作。
然而,在您采取如此大的努力之前,您应该真正问自己,这些标准的自动执行是否有足够的价值来保证解决方案的费用和难度。。您正在与一个大型团队(数十名开发人员)打交道还是一个小型团队?像代码审查这样更简单的替代方案是否足以强制执行这一点?这种强制措施将如何影响代码的质量与团队的生产力/幸福感?这些标准不执行会产生什么后果?
这些是实施此类执法之前需要考虑的重要问题。
If you are interested in enforcing a particular coding style, naming conventions, or things like that you are better off implementing custom rules for tools like FxCop or StyleCop. There really aren't any features in either the C# language or the .NET environment to help you enforce such things.
However, before you go to such lengths, you should really ask yourself whether the automated enforcement of such standards are sufficiently valuable to warrant the expense and difficulty of a solution. Are you dealing with a large team (dozens of developers) or a small one? Could simpler alternatives like code reviews be a sufficient means to enforce this? How will this kind of enforcement affect the over quality of the code vs. productivity/happiness of your team? What are the consequences of these standards aren't enforced?
These are important questions to consider before implementing such enforcement.