我该如何称呼编排 Web 应用程序的代码?
在MVC中,对于轻量级应用程序,很多人会将应用程序的逻辑放入控制器中。然而实际上,控制器应该是轻量级的,并且只负责将模型中的逻辑与视图结合起来。
我的问题:模式的名称是什么/我应该如何称呼在我的应用程序中编排逻辑的东西?从最初的阅读中,我得到的印象是这被称为“服务”,但是从那以后我读了很多东西,这让这个想法变得混乱。
In MVC, for a lightweight application, many people will put the logic of their application into the controller. However in reality the controller should be light weight and be only tasked with marrying the logic in the model with the view.
My question: What is the name of the pattern/what should I call the thing that orchestrates the logic in my application? From initial reading I got the impression this was called a "Service", however I have read many things since that have muddied that idea.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一般来说,逻辑通常位于模型中,但很难在模型/视图/控制器之间保持清晰的界限。
Generically speaking, the logic typically goes in the Model but it's difficult to keep a starkly clear line between the Model / View / Controller.
这取决于您正在使用的应用程序的类型。如果应用程序是一个轻量级应用程序,并且不会维护多年,或者不需要大量业务需求更改的灵活性,那么您几乎可以将逻辑放在您喜欢的任何地方!
话虽如此,很少有这样的应用程序(如果您打算以此谋生)不需要灵活性。因此,目前看来有些幼稚的事情,但在未来却会出现不同的结果。
来到服务模式的名称很好,但建议您查看 上的这篇文章领域驱动设计和此相关的堆栈溢出讨论。同样,对于轻量级应用程序来说,DDD 可能有点大材小用,而传统的控制器、服务、DAO 模式应该足够好了。
希望有帮助。
That would depend on the kind of application you are working with. If the application is a lightweight application and is not going to be maintained for years or doesn't need flexibility of lot of business requirement changes then you could almost put your logic anywhere you like!
Having said that, there are very few such applications (if you intend to earn living out of it) that don't need flexibility. So something that may seem naive at this point but turn out otherwise in future.
Coming to the name of the pattern Service is good but would suggest you to look at this article on Domain Driven Design and this related stackoverflow discussion. Again DDD may be overkill for a lightweight application and traditional Controller, Service, DAO pattern should be good enough.
Hope that helps.
尝试业务委托设计模式。它正是您所寻找的——编排整个应用程序逻辑。
Try Business Delegate design pattern. It does exactly what you are looking for - orchestrating the entire application logic.