0

I'm very new to MVC, and I would like to get a clarification about the function of a controller.

Imagine this primitive example:

I have 2 models and 1 controller, that gets data from both models, and I have to do a very complicated calculation with these 2 data packages. (Then give the result to a view.)

My question is:

Should I put this complicated calculation into the controller, or should I put it outside into a library? In more general form:

Am I allowed to make calculations inside a controller, or is it a bad practice?

tereško
  • 58,060
  • 25
  • 98
  • 150
Balazs Sipos
  • 167
  • 3
  • 10

2 Answers2

0

Controllers are the easy place to put this kind of logic, and become easily cluttered. Separation of concerns would take you down the path of implementing a service layer.

Community
  • 1
  • 1
felickz
  • 4,292
  • 3
  • 33
  • 37
0

Controllers should be as light as possible and have few dependencies. Your Model should handle business logic like this although you may want to put it in its own library. If you do put it in a different library, call it from the model.

marteljn
  • 6,446
  • 3
  • 30
  • 43