Results 1 to 3 of 3

Thread: I find Controller to be too complex and tightly coupled with View

  1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    159

    Default I find Controller to be too complex and tightly coupled with View

    In current usage of controllers it seams that it is not possible to simply replace View since Controller is referencing specific View components and events through both refs and eventHandlers. Should'nt View and Controller communicate through predefined set of commands without any knowledge of inner works of the other. So View would send commands like: getListOfUsers, storeUser and Controller would send commands like showLogiScreen, ShowError without referencing specific View components.

    Also wouldn't be much more simpler if Controller didn't have properties refs and control but just handler functions with the same name as events that can be triggered by the View?

    I am just saying that I have a feeling that View and Controller could be more decoupled and that Controller could be made much simpler by simply waiting for events rather then referencing specific View components and events.

  2. #2
    Sencha Premium Member Dejan Beciric's Avatar
    Join Date
    Feb 2014
    Location
    Belgrade, Serbia
    Posts
    49

    Default

    Hi,you misunderstood some MVC concepts Sencha described in tutorials.

    When something happen - view fires an event. If you want to react to that event, you need to listen for that particular event.

    So, if you have a concrete button on the view and want to react on its click event, you need to reference that particular button from controller and add a handler for that button's event.

    Also wouldn't be much more simpler if Controller didn't have properties refs and control but just handler functions with the same name as events that can be triggered by the View?
    No - controller must know which control's event to listen. Controllers could listen to events for two, or more views, or from a controls that are not on the specific view... so it could not be possible to implement as you suggested.

    I suggest you two read about events: http://docs.sencha.com/touch/2.3.1/#!/guide/events

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    159

    Default

    If we do controller like: "So, if you have a concrete button on the view and want to react on its click event, you need to reference that particular button from controller and add a handler for that button's event." then controller is tightly coupled with the view. If you change the View, and this action is no longer triggered by taping a button then you have to change controller to listen for swiping a screen to the left for instance.

    What I feel is better approach, and if it isn't I would like to be explained why it isn't, is to define tap listener on a button which fire custom event myCustomEvent and controller is then listening for that myCustomEvent and it doesn't care how this event occur.

    In this scenario you can simply replace current view with the new one where action is no longer triggered by taping a button but rather by swiping a screen. For this to work you need to define swipe listener to a panel which fires custom event myCustomEvent.

    With thi aproach you now don't need to make any changes to controller. He is still listening for that myCustomEvent and it doesn't care how this event occured.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •