Ori Bentov
Ori Bentov

Reputation: 37

should a data model hold a controller? (MVC)

I'm implementing a game in which a player has a boat and he needs to move with his boat and collect some stuff. the player has score and life as well.

I designed the system as the MVC pattern and right now I have a boatModel object which holds the data about the boat, BoatController which responsible to handle movements.

I considered making a PlayerModel object which holds the data about the player, including life, score, and the BoatController. that's because conceptually the player has his own "boat driver"

Is it make any sense that's a model object "has-a" controller (according to the MVC pattern)?

If not, how it'll be better to design it?

Thanks.

Upvotes: 1

Views: 152

Answers (1)

Sapikelio
Sapikelio

Reputation: 2604

Is not recomended having the controller inside the model. However, the visitor patter should be a good aproach for your problem although you just have a single concrete class (Your model).

Visitor Pattern (Wikipedia)

enter image description here

Upvotes: 1

Related Questions