gpt4 book ai didi

java - 非循环依赖原则 - 组件依赖循环如何成为 "morning-after syndrome"的原因?

转载 作者:行者123 更新时间:2023-11-30 23:09:30 25 4
gpt4 key购买 nike

我正在阅读 Robert Martin 撰写的“C# 中的敏捷原则、模式和实践”。目前我正在阅读非循环依赖原则(ADP)。我无法理解该部分中的一个部分。让我简短地解释一下这部分。

作者首先给出了“事后综合症”的定义。

Have you ever worked all day, gotten some stuff working, and then gone home, only to arrive the next morning to find that your stuff no longer works? Why doesn't it work? Because somebody stayed later than you and changed something you depend on! I call this "the morning-after syndrome."

然后他解释了如何解决这个问题:

The solution to this problem is to partition the development environment into releasable components. The components become units of work that can be the responsibility of a developer or a team of developers. When developers get a component working, they release it for use by the other developers. They give it a release number, and move it into a directory for other teams to use, and continue to modify their component in their own private areas. Everyone else uses the released version. As new releases of a component are made, other teams can decide whether to immediately adopt the new release. If they decide not to, they simply continue using the old release. Once they decide that they are ready, they begin to use the new release.

然后他向我们展示了一个没有任何依赖循环的组件结构的例子:

What isimportant is the dependency structure of the components. Note that this structure is a directed graph. The components are the nodes, and the dependency relationships are the directed edges.

enter image description here

然后假设一个新需求迫使我们更改 MyDialogs 中的一个类,以便它使用 MyApplication 中的一个类。您可以猜到,它会创建依赖循环:

enter image description here

然后他注意到:

The cycle forces MyApplication, MyTasks, and MyDialogs to always be released at the same time.

我的问题是:为什么? 如果我们使用可发布组件,为什么其他两个组件必须与 MyDialogs 同时发布?强>

提前致谢。

最佳答案

“循环强制...总是同时释放”实际上不是真的。

但循环依赖意味着您可以同时更改相互依赖的MyApplicationMyDialogs,然后 您必须同时释放它们。

如果您确保您的组件依赖项是非循环的,那么您永远不会被迫同时释放它们。

此外,如果在组件的第一个 版本中存在依赖循环,那么您必须在最初同时发布所有组件。

关于java - 非循环依赖原则 - 组件依赖循环如何成为 "morning-after syndrome"的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45783173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com