OOD:order.fill(warehouse) - 或-Warehouse.fill(order)

发布于 2024-12-11 00:24:42 字数 183 浏览 0 评论 0原文

哪种形式是正确的面向对象设计?
“品味问题”是平庸者的捷径。
关于这个主题有什么好的读物吗?
我想要一个决定性的证明。

编辑:我知道哪个答案是正确的(眨眼!)。我真正想要的是看到支持前一种形式的任何参数(order.fill(warehouse))。

which form is a correct OO design?
"Matter of taste" is a mediocre's easy way out.
Any good reads on the subject?
I want a conclusive prove one way or the other.

EDIT: I know which answer is correct (wink!). What I really want is to see any arguments in support of the former form (order.fill(warehouse)).

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

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

发布评论

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

评论(2

黯然 2024-12-18 00:24:42

没有确凿的证据,在某种程度上,这只是品味问题。面向对象不是科学——它是艺术。它还取决于领域、整体软件结构等,因此您的小示例不能推断为任何 OO 问题。

但是,根据您的信息,我的看法是:

仓库存储物品。他们不执行订单。命令要求的东西。他们不知道这些东西来自哪个仓库(或多个仓库)。因此,两者之间任一方向的依赖都感觉不对。

在现实世界和软件中,某些东西将成为两者之间的中介。 @themel 在对你的问题的评论中指出了同样的观点,尽管我更喜欢听起来更少的编程模式。也许是这样的:

ShippingPlan plan = shippingPlanner.fill(order).from(warehouses).ship();

然而,这是一个品味问题:-)

There is no conclusive proof and to a certain extent it is a matter of taste. OO is not science - it is art. It also depends on the domain, overall software structure, etc. and so your small example cannot be extrapolated to any OO problem.

However, here is my take based on your information:

Warehouses store things. They don't fill orders. Orders request things. They don't know which warehouse (or warehouses) the things come from. So a dependency in either direction between the two does not feel right.

In the real world, and the software, something would be a mediator between the two. @themel indicated the same in the comment to your question, though I prefer something less programming pattern sounding. Perhaps something like:

ShippingPlan plan = shippingPlanner.fill(order).from(warehouses).ship();

However, it is a matter of taste :-)

柠檬色的秋千 2024-12-18 00:24:42

最简单的形式仓库是库存存储场所。
但是,将仓库视为由存储空间、个人、装运码头等组成的设施也是正确的。如果您假设仓库的视图,那么可以适当地说仓库(作为设施)可以收费填写订单或扩展形式:

仓库设施能够根据给定的规格(订单)组装货物。

以上是以下理由(如果不是证据): warehouse.fill(order);< /代码> 形式。请注意,此形式基本上等同于 SingleShot 和主题的建议。诀窍是整合 ShippingPlanner(订单履行机构)和仓库(库存存储空间)。简而言之,在我的示例中,仓库是由订单履行机构库存存储空间组成的,在 SingleShot 中,这两者是分开呈现的。这意味着,如果这种合并是(或变得)不可接受的(例如由于零件的复杂性),那么仓库可以分解为这两个子组件。

我无法想出将 fill 操作分配给 order 对象的理由。

你好?仓库?是的,请接受此订单并填写。谢谢。——我能理解。

嘿,命令!仓库在那边。做你的事并实现自己。——对我来说毫无意义。

In its simplest form warehouse is an inventory storage place.
But it also would be correct to view a warehouse as a facility comprised of storage space, personal, shipping docks etc. If you assume that view of a warehouse then it would be appropriate to say that a warehouse (as a facility) can be charged with filling out orders, or in expanded form:

a warehouse facility is capable of assembling a shipment according to a given specification (an order)

above is a justification (if not proof) for: warehouse.fill(order); form. Notice that this form substantially equivalent to SingleShot's and themel's suggestions. The trick is to consolidate shippingPlanner (an order fulfillment authority) and a warehouse (a inventory storage space). Simply put in my example warehouse is a composition of an order fulfillment authority and an inventory storage space and in SingleShot's those two are presented separately. It means that if such consolidation is (or becomes) unacceptable (for example due to complexity of the parts), then the warehouse can be decomposed into these two sub components.

I can not come up with a justification for assigning fill operation to an order object.

hello? warehouse? yes, please take this order and fill it. thank you. -- that I can understand.

hey, order! the warehouse is over there. do your thing and get fulfill yourself. -- makes no sense to me.

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