在 MVC/MVP/MVPC 中,您将业务逻辑放在哪里? [英] in MVC/MVP/MVPC where do you put your business logic?

查看:33
本文介绍了在 MVC/MVP/MVPC 中,您将业务逻辑放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 MVC/MVP/MVPC 设计模式中,您将业务逻辑放在哪里?不,我不是指 ASP.NET MVC 框架(又名Tag Soup").

in the MVC/MVP/MVPC design pattern where do you put your business logic? No, I do not mean the ASP.NET MVC Framework (aka "Tag Soup").

有人说你应该把它放在MVC/MVPC中的Controller"或Presenter"中.但是,其他人认为它应该是模型的一部分.

Some people say you should put it in the "Controller" in MVC/MVPC or "Presenter". But, others think it should be part of the Model.

你怎么看,为什么?

推荐答案

我是这样看的:

控制器用于应用逻辑;特定于您的应用程序希望如何与其相关的知识领域交互的逻辑.

The controller is for application logic; logic which is specific to how your application wants to interact with the domain of knowledge it pertains to.

该模型用于独立于应用程序的逻辑.即在其相关知识领域的所有可能应用中都有效的逻辑.

The model is for logic that is independent of the application. i.e. logic that is valid in all possible applications of the domain of knowledge it pertains to.

因此,几乎所有业务规则都将在模型中.

Hence nearly all business rules will be in the model.

当我需要决定将某些逻辑放在哪里时,我发现一个有用的问题可以问自己:这总是正确的,还是仅针对我当前正在编写的应用程序的一部分?"

I find a useful question to ask myself when I need to decide where to put some logic is "is this always true, or just for the part of the application I am currently coding?"

这篇关于在 MVC/MVP/MVPC 中,您将业务逻辑放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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