可以按合同设计允许我强制执行私有方法

可以按合同设计允许我强制执行私有方法

本文介绍了可以按合同设计允许我强制执行私有方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法用语言做到这一点如何强制私有方法,因为接口方法仅是公开吗?

I can't do this with languageHow to enforce private method since interface methods are only public?

那么我可以改为按合同使用设计吗?

so can I use design by contract instead ?

推荐答案

如果您想强制执行特定的编码样式,命名约定或类似的事情,最好为 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.

这篇关于可以按合同设计允许我强制执行私有方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 19:00