2 Replies - 152 Views - Last Post: 05 February 2012 - 11:31 PM Rate Topic: -----

Topic Sponsor:

#1 Skod  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-February 12

What is indirect assocations (Ex. MVC-Model)?

Posted 05 February 2012 - 02:05 PM

Hello :)

I'm trying to figure out the MVC-model, and there is mentioned something about "indirect associations"? Can anyone please explain this to me? :)

Still new on these forums and I couldn't find a UML category or something like that, sorry if this is the wrong spot. :)

Is This A Good Question/Topic? 0
  • +

Replies To: What is indirect assocations (Ex. MVC-Model)?

#2 skaoth  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 90
  • View blog
  • Posts: 601
  • Joined: 07-November 07

Re: What is indirect assocations (Ex. MVC-Model)?

Posted 05 February 2012 - 03:39 PM

The whole point of MVC is separation of concerns. What is meant by this, is that the different components of your application should know as little as possible about the other components to that you don't have a highly coupled system.

With MVC, The controller generally knows about both the view and model.
When implementing the controller you will usually do something like this

public class MyController {
    MyView view;
    Model model;
    
    public MyController(MyView view, Model model) {
        view.addCoolEventListener(new ActionListener() { ... })
    }
...
}



The controller above has a "direct" association with both the Model and View because it has to know about them.

The "indirect" association is generally done using the observer pattern.
The example is the View in MVC
public class MyView {

  public void addCoolEventListener(ActionListener event) {...}
}



Here the view allows other objects to know that the view did something.
In our case the controller created an "indirect" relationship by registering for the "CoolEvent" event.

This post has been edited by skaoth: 05 February 2012 - 03:44 PM

Was This Post Helpful? 3
  • +
  • -

#3 Skod  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-February 12

Re: What is indirect assocations (Ex. MVC-Model)?

Posted 05 February 2012 - 11:31 PM

Oh! That makes sense! Thank you very much! :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1