Search code examples
flashapache-flexmodel-view-controllercommandrobotlegs

RobotLegs Domain logic - where to place it


In Robotlegs does the domain logic needs to be in the Commands(controller) or the Models?

Example: lets say i'm building a "Tic Tac Toe" game. i have: GameMadiatore,CellSelectedCommand,BoardModel.

After the user clicks on a cell the "GameMadiatore" fires an event that initiates "CellSelectedCommand". Does the "find 3 in row" win logic needs to be in the "BoardModel" or "CellSelectedCommand" or some other command?


Solution

  • I would advise you to create atomic commands.

    This means a command should do 1 thing and 1 thing only. This allows you to easily rewire your application logic without refactoring too much later on.

    In the case described above your thinking is correct another command will do just fine. For example:

    • CellSelectedCommand
    • Check3InRowCommand
    • StartNewGameCommand
    • PlayerWinsCommand
    • ..

    Some more principles about MVCS:

    • Mediator: Should be considered as a mail man. It will act as a go-between between your views and your application. Call it a ViewController if you will, but then a bit more rudimentary.
    • Command: Can be considered as the controller logic, all the decision making can be done here. Update your models from here.
    • Model: Should only reflect application state. For example a boolean that indicates whether the game has been won.

    Cheers