简体   繁体   English

这是业务逻辑吗?

[英]Is this business logic?

Suppose I have a class Calculator that perform some basic operation like sums or divisions. 假设我有一个Calculator类,它执行一些基本运算,如求和或除法。 where should I put it in the MVC pattern? 我应该把它放在MVC模式的什么地方? Is this business logic ? 这是业务逻辑吗?

I've find nothing that explain clearly what kind of logic is this. 我没有发现任何东西可以清楚地解释这是什么逻辑。

Sorry for mistakes but I'm not English. 对不起,但我不是英语。

Yes, this is business logic. 是的,这是业务逻辑。 It should be in the model. 它应该在模型中。 Let's say you have an advanced calculator with factorial, square or cube functions. 假设您有一个具有阶乘,平方或立方函数的高级计算器。 When they stay in the model, this allows you to use them in different GUI applications. 当它们保留在模型中时,这使您可以在不同的GUI应用程序中使用它们。

A common confusion is model is just data; 一个普遍的困惑是模型仅仅是数据;模型只是数据。 it is not. 它不是。 It contains business logic as well. 它还包含业务逻辑。

Yes this is exactly business logic, what's more to achieve more proper design it should be injected to controller via interface (ICalculator). 是的,这完全是业务逻辑,此外,要实现更正确的设计,还应该通过接口(ICalculator)将其注入控制器。 This example is extremely simple but I imagine your controller could have 4 actions (add, subst, mult, div) with 2 params each. 这个例子非常简单,但是我想您的控制器可以有4个动作(add,subst,mult,div),每个动作有2个参数。 Controller would validate inputs (not to div by 0) and use the ICalculator instance to perform the calculations. 控制器将验证输入(而不是除以0的div),并使用ICalculator实例执行计算。

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

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