I am making a game of Monopoly. I call a method in my Board class which returns the current players square object! E.g Old Kent Road. Euston, Chance , Free parking. I use polymorphism to decide upon the logic of what should happen depending of the state of the square! E.g I’ll have a property class where a the polymorphic method would run logic to check if it’s owned then show a view which tells the current player how much they owe. However if it is for sale then show a view which shows how much it is to buy with two options to the user 1. Buy 2. Don’t buy
However if we land on a chance, using polymorphism something totally different will occur, all I have to do in my controller or my model is call action() for the logic. It works fine.
Now. My problem
How from the model can I decide what view should be rendered ? An option is to put all the logic in the controller and get the current type of square! But that’s messy and will consist of a lot of conditionals. E.g.
If(typeOfSquare === chance ){
// get the latest chance and call a
View method to render it with options to the user
}
I would rather use polymorphism and have and build my logic of the square in seperate classes. E.g ChanceSquae or PropertySquare but that would mean building a property on the square called something like htmlView which will store the html that I can get from the square object and then pass into the view.
This seems like an impossible situation to deal with without getting messy!!