2

我刚刚通过 NDepend 运行我的一个项目,报告将我的程序集放在痛苦区域的角落。我只是想知道这是否是我应该担心的事情。

疼痛区的真正含义是什么?这不是说有很多耦合,事情不能很容易改变。

我最近删除了很多接口并密封了很多类,因为我不希望用户扩展 API(仅在某些地方)。它是 com 对象的 .NET 包装器,因此用户不需要扩展任何东西。

有什么好方法可以让我走出痛苦的境地?

谢谢

4

2 回答 2

11

The idea of Zone of Pain is to detect components that both: -Are concrete (i.e their users are binded with classes instead of interfaces) -Are popular (i.e they are used by a lot of other components).

Popular refers to the notion of stability. A component is stable if when changed, it breaks a lot of other components that are using it. In a word: Popular = Stable

Another idea is that interfaces are less subject to changes than classes. This is why it is commonly accepted that it is preferable to use an interface instead of a class, you have less chance to be 'statically' broken + you have less chance to be 'semantically' broken, since your code is not supposed to be bound with any implementations details (that are highly subject to changes).

As a consequence, being concrete + stable expose a component to some potential development pain: it is highly subject to changes + each changes will potentially break a lot of code.

In your case and some other cases, being in the Zone of Pain is not necessarily a bad thing. The important thing is to both be aware of this fact + if indeed your component provokes Pain, then roll back your code to interfaces.

于 2009-07-14T09:32:50.823 回答
3

我认为 Scott Hanselman 写了一篇关于 NDepend 及其区域影响的相当长的文章

http://www.hanselman.com/blog/ExitingTheZoneOfPainStaticAnalysisWithNDepend.aspx

正如他所说,我也同意,在痛苦地带徘徊的集会不一定是坏事。然而,当决定使用另一个组件(COM 或其他)来实现同一层功能时,这表明您需要进行更改。

要问的问题可能是,“我们将这一层换成另一个框架/库的可能性有多大?”

于 2009-07-13T10:07:15.737 回答