面向对象模型中平衡类职责分配的示例

发布于 2024-12-14 08:16:21 字数 160 浏览 6 评论 0原文

在 Bochs 等人的“统一建模语言用户指南”中。等人。 “第 4 章:类”中有一个(子)部分,标题为“对系统中的责任分配进行建模”。它谈论平衡责任,这可能导致类的分裂或合并。

您能否举例说明这种“责任平衡”是什么样子的?

In "The Unified Modelling Language User's Guide" by Bochs et. al. there is in 'Chapter 4. Classes' there (sub)section titled "Modeling the Distribution of Responsibilities in a System". It talks about balancing responsibilities, which can lead to splitting or coalescing of classes.

Could you give me example how such "balancing of responsibilities" might look like?

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

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

发布评论

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

评论(1

七秒鱼° 2024-12-21 08:16:21

我认为当班级既不太小也不太大时,就会发生“责任平衡”。如果职责没有很好地平衡,那么对象模型中就会有一些大的类承担太多的职责。或者更糟糕的是,有一个对象可以完成所有工作。这有时被称为“上帝对象”。它被认为是一种反模式。谷歌“上帝对象”。

拥有 God 对象的一个​​相关后果是拥有许多小类,这些类除了封装数据之外几乎不做任何事情。当职责得到很好的平衡时,每个类都有一组明确定义的服务,并拥有足够的属性和方法来履行这些职责。

维基百科将均衡的责任称为“馄饨代码”,但我以前从未听说过这个术语。

I think "balancing of responsibilities" happens when classes are neither too small nor too large. If responsibilities are not well balanced, then the object model has a few large classes that have too many responsibilities. Or even worse, there is a single object that does all the work. This is sometimes called the "God object". It is considered an anti-pattern. Google "god object".

A related consequence of having a God object is having many small classes that do very little other than encapsulate data. When responsibilities are well balanced, every class has a set of well-defined services and holds just enough attributes and methods to fulfill those responsibilities.

Wikipedia refers to well-balanced responsibilities as "ravioli code", but I had never heard that term used before.

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