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

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

问题描述

在MVC/MVP/MVPC设计模式中,您将业务逻辑放在哪里?不,我不是说ASP.NET MVC框架(也称为标签汤").

有人说您应该将其放在MVC/MVPC或"Presenter"的控制器"中.但是,其他人则认为它应该是该模型的一部分.

您怎么看?为什么?

解决方案

这是我的看法:

控制器用于应用程序逻辑;逻辑,特定于您的应用程序希望如何与其所涉及的知识领域进行交互.

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

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

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

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").

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.

What do you think and why?

解决方案

This is how I see it:

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天全站免登陆