业务层门面VS杂糅的业务组件 [英] Business Layer Facade vs Mingled Business Components

查看:137
本文介绍了业务层门面VS杂糅的业务组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在设计一个大型应用程序的基础。我们正在与数据层使用EF传统的3层系统准备,在业务层和MVC / WCF的UI层素雅的C#类。我们都在原型应用程序的足够认识到这会为我们工作,但是由于业务需求的的复杂性将是常见的一些业务组件的与人交往。

I'm currently designing the foundation for a large application. We are going with the traditional 3 tier system using EF in the data layer, plain jane c# classes in the business layer and MVC / WCF for the ui layer. We have prototyped enough of the application to realize that this will work for us, however due to the complexity of the business requirements it will be common for some of the business components interact with one another.

考虑以下两个业务组件:

Consider the following two business components:


  • RetailManager - 一切系统到零售相关的应对

  • CartManager - 优惠的一切相关的购物车体验

这两个交互,例如,在结帐过程中,当一个项目被购买。需要为购买商品的库存减少。

The two interact, for instance, during the checkout process when an item is purchased. The inventory for the purchased item needs to be reduced.

下面是我的思维过程,到目前为止:

Here is my thought process so far:


  1. 让业务组件相互引用,并确保循环引用永远不会发生(CartManager引用RetailManager,但从来没有的其他方式)。 结帐将是对CartManager类中的方法,它会呼吁RetailManager的方法来调整库存。虽然这工作,我不知道它会如何扩展和维护费用将是什么随着时间的推移。它不觉得100%的正确给我。

  1. Let business components reference each other and ensure cyclical references never happen (CartManager references RetailManager, but never the other way). "Checkout" would be a method on the CartManager class, and it would call a method on the RetailManager to adjust inventory. While this will work, I'm not sure how well it will scale, and what the maintenance cost will be over time. It doesn't feel 100% "right" to me.

创建业务组件和UI层之间的门面。在这个例子中,正面将具有检验方法和两者管理者参考。我喜欢这种方法比第一种,但是我知道,不是所有的业务对象都需要一个门面,我不希望创建一吨门面类正好有通过方法都是空关。

Create a Facade between the business components and the UI tier. In this example, the Facade would have the checkout method and a reference to both managers. I like this approach more than the first, however I know that not all of my business objects will need a Facade, and I don't want to create a ton of Facade classes just to have empty pass through methods.

我倾向于2,与需要的地方我只会造成外观类的告诫。用户界面层将有机会获得这两个门面和业务层组件和必须知道什么时候使用它(唯一的一部分,我不喜欢这个解决方案)。

I'm leaning towards 2, with the caveat that I will only create facade classes where needed. The UI tier will have access to both the Facade and the business layer components and will have to know when to use which (the only part I don't like about this solution).

我已经做了很多的研究,但一直没能来拿出,感觉完全正确的解决方案。

I've done a lot of research but haven't been able to come to come up with a solution that feels completely right.

在使用这种方式的外观模式,或者其他的想法来解决这个问题有什么想法都欢迎。

Any thoughts on using the facade pattern in this way, or other ideas to solve the problem are welcome.

先谢谢了。

推荐答案

我倾向于去与门面的实现。

I would tend to go with facade implementation.

我会先问自己,其职责是确保当结账发生库存减少?我不认为这是 CartManager 的责任,以减少库存。我想有一个可以确保每当一个项目是由 CartManager 签出,相应的项目从库存减少第三类(在你的情况门面)。

I would first ask myself, whose responsibility is it to make sure that inventory is reduced when a checkout happens? I don't think it is responsibility of CartManager to reduce the inventory. I would have a third class (in your case facade) that makes sure that whenever an item is checked out by CartManager, corresponding item is reduced from inventory.

我会考虑的另一个选择是基于事件的实现。 CartManager 将提高每当一个项目是签出 ItemCheckedOut 事件。 RetailManager 将订阅该事件,每当一个事件引发将减少库存。如果你是新的事件驱动的设计,遵循在Quora上这个问题 - 的http://www.quora.com/What-are-some-good-resources-on-event-driven-software-design

Another option I would consider is event based implementation. CartManager would raise a ItemCheckedOut event whenever an item is checked out. RetailManager would subscribe to this event and would reduce the inventory whenever an event is raised. If you are new to event driven design, follow this question on quora - http://www.quora.com/What-are-some-good-resources-on-event-driven-software-design

这篇关于业务层门面VS杂糅的业务组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆