Reputation: 831
Assume my friend and I are writing a chess-game for Android and want to use an MVC pattern.
I have no experience with MVC pattern, and not sure where to implement core logic and UI behavior.
Where must logic be located (such as validating and making a move)?
Where must UI behaviors be located (such as animating game board and pieces)?
Upvotes: 0
Views: 201
Reputation: 8749
Model = Data Objects which represent your game (such as player info, the board, pieces and scores, but virtually no logic/behavior)
View = UI Elements, UI behaviors (such as animations, updating graphics, etc) - but nothing that qualifies as business logic, state management, nor persistence. Views are generally "reactive" and "interactive" meaning they change based on Model changes, and the user uses them to interact with one or more controllers.
Controller = Validation, Logic, Model/State management, Persistence, etc. Controller would expose methods that the View can invoke as Actions (such as moving a peice). Upon invoking these action methods the model may change, in response to model changes your view should update (usually through data-binding, an Event, well-known registered Interface or Callback method.
Upvotes: 1
Reputation: 1245
game logic will be in service layer call from Controller class. You can use jsp or any other template engine for view purpose. In the view you display chessboard and with javascript implement drag drop logic to move pieces. Use ajax call to submit move.
Upvotes: 1
Reputation: 3712
neither i would put it in a lib section. you can maybe store moves and their history in the model, and then call the moves in the controller but do a bulk of your validation in files in a lib section.
you can also store the time elasped for a timed game in the model.
if you made this as a responsive web app you could have different views for android and maybe tablets and desktop. maybe a view for mouse users and touch screens.
Upvotes: 0
Reputation: 489
basically rules (being games rules or business rules) are in Model side of MVC.
control is just the "middle man" that asks Model for services and determines the appearance of View. Your very basic classes like GameState , GameRule, Player or Pawns must be defined as Models.
Upvotes: 1