面向对象模型中平衡类职责分配的示例
在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为当班级既不太小也不太大时,就会发生“责任平衡”。如果职责没有很好地平衡,那么对象模型中就会有一些大的类承担太多的职责。或者更糟糕的是,有一个对象可以完成所有工作。这有时被称为“上帝对象”。它被认为是一种反模式。谷歌“上帝对象”。
拥有 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.