Is it dangerous for me to give some of my Model classes Control-like methods?

Posted by Pureferret on Programmers See other posts from Programmers or by Pureferret
Published on 2012-09-17T12:24:30Z Indexed on 2012/09/17 15:52 UTC
Read the original article Hit count: 210

In my personal project I have tried to stick to MVC, but I've also been made aware that sticking to MVC too tightly can be a bad thing as it makes writing awkward and forces the flow of the program in odd ways (i.e. some simple functions can be performed by something that normally wouldn't, and avoid MVC related overheads).

So I'm beginning to feel justified in this compromise:

I have some 'manager programs' that 'own' data and have some way to manipulate it, as such I think they'd count as both part of the model, and part of the control, and to me this feels more natural than keepingthem separate. For instance: One of my Managers is the PlayerCharacterManager that has these methods:

void buySkill(PlayerCharacter playerCharacter, Skill skill);
void changeName();
void changeRole();
void restatCharacter();
void addCharacterToGame();
void createNewCharacter();
PlayerCharacter getPlayerCharacter();
List<PlayerCharacter> getPlayersCharacter(Player player);
List<PlayerCharacter> getAllCharacters();

I hope the mothod names are transparent enough that they don't all need explaining.

I've called it a manager because it will help manage all of the PlayerCharacter 'model' objects the code creates, and create and keep a map of these. I may also get it to store other information in the future.

I plan to have another two similar classes for this sort of control, but I will orchestrate when and how this happens, and what to do with the returned data via a pure controller class. This splitting up control between informed managers and the controller, as opposed to operating just through a controller seems like it will simplify my code and make it flow more.

My question is, is this a dangerous choice, in terms of making the code harder to follow/test/fix? Is this somethign established as good or bad or neutral? I oculdn't find anything similar except the idea of Actors but that's not quite why I'm trying to do.

Edit: Perhaps an example is needed; I'm using the Controller to update the view and access the data, so when I click the 'Add new character to a player button' it'll call methods in the controller that then go and tell the PlayerCharacterManager class to create a new character instance, it'll call the PlayerManager class to add that new character to the player-character map, and then it'll add this information to the database, and tell the view to update any GUIs effected. That is the sort of 'control sequence' I'm hoping to create with these manager classes.

© Programmers or respective owner

Related posts about design-patterns

Related posts about architecture