哪种设计支持低耦合?

发布于 2024-11-02 13:15:30 字数 151 浏览 3 评论 0原文

设计 #1

设计#2

哪种设计支持整体低耦合?为什么?

Design #1

Design #2

Which Design supports overall low coupling? and why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

捶死心动 2024-11-09 13:15:30

在第一个中,付款与销售相结合。在第二个中,它与注册和销售相结合。我想说第一个耦合度较低,因为 Register 没有支付的概念。付款可以完全消除,并且不需要对注册进行任何更改。在第二种情况下,如果您取消了“付款”,则“注册”和“销售”都需要更改。

In the first one payment is coupled to Sale. In the second one its coupled to Register and Sale. I would say the first has lower coupling because Register has no concept of payment. Payment could completely eliminated completely and would require no changes to Register. In the second if you eliminated Payment both Register and Sale would need to change.

烟若柳尘 2024-11-09 13:15:30

In first one Payment is created by Sale so this is more coupled.

in second one there is low coupling with dependency injection - http://en.wikipedia.org/wiki/Dependency_injection , witch is a design pattern that separates behavior from dependency resolution, thus decoupling highly dependent components. Payment and Sale were highly dependent in first picture.

入画浅相思 2024-11-09 13:15:30

我不明白第一个例子的要点。不需要注册吗?

在第二个示例中,可以使用任何类型的付款。 (签证、现金等)。因此它的耦合更加松散。

I don't see the point in the first example. Register is not needed?

In the second example any kind of payment can be used. (Visa, cash etc). Hence it's more loosely coupled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文