Should methods that manipulate the Model class members be implemented in the Model or in the Controller? Does it depend on how “heavy” this manipulation is ?
By “manipulation” I mean:
-
get a class member
-
make a long calculation based upon this class member
-
return another value which relates to this class
For example, a Board class which hold a cell matrix member.
Now I want to implement a method which returns all the surrounding cells according to specific cell location.
Is the model or view responsible to for implementing the above ?
If this question belongs to another Stack Exchange QA site I will welcome the recommendation to move my post to that site.
What you call "model" is are actually domain objects. The actual model in MVC is just a layer, not concrete thing.
In your particular example, the
Boardshould have a method that returns this list. I assume, that you are actually acquiring it because you then need to do further interaction with those cells.This is where the services within the model layer comes in to play. If you use them, they are the outer part of model layer and contain the application logic – interaction between different domain objects and the interaction between the persistence (usually either data mappers or units of work) and domain objects.
Controller does not care about the details of what service does. And it should not receive any feedback. When execution gets to the view, it request from model layer the latest changes and modifies the UI. As the added benefit – services let you stop the business logic from leaking in the presentation layer (mostly made up from views an controllers).
The domain object should contain only methods, that deal with their state.