简体   繁体   English

建筑/设计模式问题

[英]An Architectural / Design Pattern Question

So yesterday my mate and myself had this duscussion about the architecture of this e-shopping website that im developing. 因此,昨天我的同伴和我对正在开发的这个电子购物网站的架构产生了疑问。 Note that I work with ASP.NET for this. 请注意,我为此使用ASP.NET。 He was quite surprised to learn that I do not keep the Items added to the shopping-cart in an ArrayList or other Generic list but rather i insert them straight to the database using LINQ To Entities. 他很惊讶得知我没有将添加到购物车中的项目保留在ArrayList或其他通用列表中,而是使用LINQ To Entities将它们直接插入数据库中。 Could I pass only for this web app and not use n-tire or should I do as my friend suggested which is, have methods that perform updates, deletions etc.. I highly appreciate your feedback as this is a very important dilemma for me. 我只能通过此Web应用程序并且不使用n-轮胎,还是应该按照我的朋友的建议进行操作,即具有执行更新,删除等方法。我非常感谢您的反馈,因为这对我来说是一个非常重要的难题。 Thank you! 谢谢!

I think there are two things to think about here: 我认为这里有两件事要考虑:

One of the worst things you can do is over design, and create a N-Tier system when it isn't needed. 您可以做的最坏的事情之一就是过度设计,并在不需要时创建N-Tier系统。 If there isn't a need to have a Data Access layer, don't throw one in there. 如果不需要数据访问层,请不要在其中扔一个。

Find out the demands on your system, if you have a need to be able to scale out then you are going to have to design your system in tiers, and use data access methods that are more scalable, as well as services to get/update your data. 找出对系统的需求,如果您需要能够进行横向扩展,那么您将不得不按层设计系统,并使用可扩展性更高的数据访问方法以及用于获取/更新的服务您的数据。

Second, whether or not you should be throwing these things into a database, as the user adds things to a shopping cart. 其次,当用户将东西添加到购物车时,是否应该将这些东西扔到数据库中。 I don't think this is necessarily an n-teir problem. 我认为这不一定是一个难题。 Trips to the DB are costly, esp when you could just store them client/session side until.. 到数据库的旅行是昂贵的,尤其是当您可以将它们存储在客户端/会话端之前。


With that being said, I personally like to use a Data Access Layer, I find that it makes code cleaner, and it makes you standardize how you access and change your data. 话虽如此,我个人喜欢使用数据访问层,我发现它使代码更清洁,并且使您可以标准化访问和更改数据的方式。 Instead of each class/method being able to change data adhoc, they have to do it through a well defined set of interfaces in the DAO layer that you can control, audit, etc. By using a DAO layer it also helps facility mocking, which is invaluable when it comes to testing. 他们不必通过每个类/方法都可以更改数据自定义,而必须通过DAO层中一组定义明确的接口来执行此操作,您可以控制,审计等操作。通过使用DAO层,它还可以帮助进行设施模拟,从而在测试方面是无价的。

References for N-Teir development: N-Teir开发参考:

  1. First just understand what you are trying to accomplish! 首先,只需了解您要完成的任务!
  2. What is N-Teir Architecture 什么是N-Teir架构
  3. Asp.net Tutorial Asp.net教程
  4. MSDN on Application Design (From N-Tier to .NET) MSDN上的应用程序设计(从N层到.NET)

Let me make sure that I understand: As items are added to the shopping cart you're persisting them right away rather than waiting until the session is completed to do them as a single unit of work. 让我确保我理解:将项目添加到购物车后,您将立即保留它们,而不必等到会话完成才将其作为单个工作单元来完成。 You aren't concerned about transactions here, so you must have the session id and some kind of flag to indicate whether or not an item is purchased. 您不必担心此处的交易,因此您必须具有会话ID和某种标记以指示是否购买了商品。 When the customer indicates that they want to buy, your program queries for all the items associated with that session and updates all their purchased flags as a single unit of work. 当客户指示要购买时,您的程序将查询与该会话相关的所有项目,并将所有购买的标记更新为一个工作单元。

Is that a correct summary? 那是正确的摘要吗?

You've made a choice of how to handle committing your shopping cart as a single unit of work. 您已经选择了如何将购物车作为单个工作单元来处理。 I think there's more than one way to do things, and your way is defensible. 我认为做事的方法不只一种,而且您的方法是可以辩护的。

But I disagree with the comment about over-engineering. 但是我不同意关于过度工程的评论。 A layered architecture isn't that difficult to construct. 分层架构并不难构建。 It centralizes your persistence logic in one well defined package that you can test separately and put aside. 它将持久性逻辑集中在一个定义明确的程序包中,您可以对其进行单独测试并放在一边。

There are a lot of virtues in the layered approach. 分层方法有很多优点。 All of development is a problem of managing complexity by partitioning large problems into smaller, more manageable ones. 所有开发工作都是通过将大问题划分为更小,更易于管理的问题来管理复杂性的问题。 We use objects and packages to do this. 我们使用对象和包来执行此操作。 I think it's a better approach as your system grows. 我认为随着系统的发展,这是一种更好的方法。 It's one reason why client/server isn't as widely used as it was 15-20 years ago. 这是为什么客户端/服务器没有像15-20年前那样被广泛使用的原因之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM