Is this business logic?

64 views Asked by At

Suppose I have a class Calculator that perform some basic operation like sums or divisions. where should I put it in the MVC pattern? 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.

2

There are 2 answers

0
zar On

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.

A common confusion is model is just data; it is not. It contains business logic as well.

0
Łukasz Zwierko On

Yes this is exactly business logic, what's more to achieve more proper design it should be injected to controller via interface (ICalculator). This example is extremely simple but I imagine your controller could have 4 actions (add, subst, mult, div) with 2 params each. Controller would validate inputs (not to div by 0) and use the ICalculator instance to perform the calculations.