库存立面设计模式
我想知道是否有人可以给我一个例子,说明如何在库存系统中使用外观模式。我的库存是咖啡、百吉饼和披萨,
我确实编写了一个状态类来检查订单和交货。
我不是要求别人编写代码,我只需要一些带有任何实现的简单类。
我只想能够订购库存,检查库存是否不足,检查库存,添加,删除,现有库存..
在库存中使用门面听起来合理吗?
productFacade Interface class
inventory class
bagel class implements inventory(adding,deleting, stock on hand)
pizza class implement inventory
coffee class implements inventory
使用门面模式与订单是否合理?
orderfacade
order class(create order)
address class(for delivery of pizza, bagel,etc)
orderline
basket item
我正在尝试将外观模式强加到我的程序中。 我的程序已经使用抽象工厂来创建披萨。咖啡和百吉饼调味品的装饰器。
I was wondering if someone could give me an example of how i could use the facade pattern in an inventory system. My inventory is coffee, bagles, and pizza
I did write a state classes for checking on an order and delivery..
I am not asking someone to write code i just need some simple classes with any implementation.
I just want to be able to order inventory, check if stock is low, check inventory, add, delete, inventory on hand..
does this sound reasonable to use the facade in an inventory?
productFacade Interface class
inventory class
bagel class implements inventory(adding,deleting, stock on hand)
pizza class implement inventory
coffee class implements inventory
Is it reasonable to use he facade pattern with an order?
orderfacade
order class(create order)
address class(for delivery of pizza, bagel,etc)
orderline
basket item
I am trying to force the facade pattern into my program.
my program already uses abstract factory for pizza creation. decorator for condiments on the coffee and bagel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
外观的主要目的是将复杂的子系统或一组对象/接口包装成一个更简单的子系统或对象/接口。基本上,它使客户端无需了解太多实现细节和/或所有必要的依赖项,然后将工作委托给客户端的子系统。如果子系统本身的某些部分过于复杂,立面甚至可以包裹其他立面。
正如亚历克斯提到的,思考问题的一个好方法是假装你是客户。你去商店点了一个百吉饼和一杯咖啡。就你而言,你应该只需要让服务员(门面)给你一份大双人份和一个百吉饼,里面有香草和大蒜奶油奶酪。然后服务员会处理细节,比如煮咖啡、倒咖啡、烤百吉饼和涂奶油奶酪。您也可以将烤面包机视为门面。服务员只关心将百吉饼放进去并将滑块推下。他不需要知道烤面包机如何转换电流来加热线圈并烤百吉饼。
因此,将排序逻辑分解为有用的步骤,然后封装客户端不需要知道外观可以为客户端执行的操作(或委托给其他东西)的实现细节。
希望有帮助。我正要出门,所以没有时间查看代码示例。如果问题还没有找到好的答案,也许今晚晚些时候。
A facade's main purpose is to wrap a complex subsystem or set of objects/interfaces into a simpler one. Basically, it decouples a client from needing to know too many implementation details and/or about all the necessary dependencies and then delegates the work down to the subsystem for the client. Facades can even wrap other facades if certain parts of the subsytem itself is too complex.
As Alex mentioned, a good way to think of things, is pretend you're the client. You go to the shop and order a bagel and a coffee. As far as you're concerned, you should just need to ask the waiter (the facade) to get you a large double-double and a bagel with herb and garlic cream cheese. The waiter will then take care of the details, such as making the coffee, pouring the coffee, toasting your bagel and spreading the cream cheese. You could consider the toaster a facade as well. The waiter is only concerned with putting the bagel in and pushing the slider down. He doesn't need to know how the toaster converts the electrical current in order to heat the coils and toast the bagel.
So break your ordering logic into useful steps and then encapsulate the implementation details that the client should not need to know that the facade can do for the client (or delegate to something else).
Hope that helps. I'm on my way out the door so I don't have time for a code sample. Maybe later tonight if the question isn't already loaded with good answers.
考虑一下您(客户)需要做什么才能喝到一杯咖啡。在你的外观中,你会有类似的东西
,在内部你会有类似的东西
,外观简化了你与对象的交互。
think about what needs to be done for you (client) to get a cup of coffee. in your facade, you would have something like
and internally you would have something like
in general, facade simplifies your interaction with the object.