Solved

MVC with a twist.

Posted on 2006-11-09
4
387 Views
Last Modified: 2013-11-24
Hi all,

Old programmer, getting there with Java, new to GUI.

I want to put together a GUI that handles interrelated models. The model is a Person object in a family tree. The view will initially just be a box with the person's details shown in it, linked with lines to parents, siblings and children. The controller will obviously bind these two together.

I want to allow the user to move from person to person, up to parents, left/right to siblings and down to children, probably with cursor keys.

My problem is this. The view can recognise the user operation, say 'select father'. It must then ask the model (a Person object) to identify which person is its father. But how can that mechanism then indicate which controller or view should be signalled to take focus?

Clearly I could create a Map that lets me find the controller responsible for the parent of the person but this feels like breaking the whole advantage of the MVC pattern. Is there a 'good' way of dealing with this?

Paul
0
Comment
Question by:PaulCaswell
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
jaggernat earned 250 total points
ID: 17910766
View represents the front-end User Interface.
Controller represents the object which gets the values from user interface, calls appropriate classes and forwards a response back to the view.
Model represents the Object which holds the information in the front-end view and passes it over to the controller when controller is invoked

>>>But how can that mechanism then indicate which controller or view should be signalled to take focus?

You would have a single "controller" which would control the entire application.
You would have multiple "views", for parents , children, siblings, ect and you would have their corrosponding objects as Models.

I am not sure if you have followed the MVC architecture correctly.

Some refrences which might help:

http://www.enode.com/x/markup/tutorial/mvc.html
http://cristobal.baray.com/indiana/projects/mvc.html

 

0
 
LVL 16

Author Comment

by:PaulCaswell
ID: 17913241
>>I am not sure if you have followed the MVC architecture correctly.
LOL :-)

Nice links! I'll browse through those later.

So the Model is the object, a Person object in my case. This has the responsibility of HOLDING the data.

The box with text in is the View. This has the rsponsibility of DISPLAYING the data.

Who controls user interaction, the view or the controller?

It the data is interrelated at both the model level and the view level (parent, child, sibling) and the controller distributes UI events to the view, how can the view indicate to the controller that focus should be changed or window should be scrolled for example?

Do you see my quandary? I fully agree that the model must be separated from the view, that would allow me to change the view seamlessly, but how can the view tell the controller to scroll the window if it is independent of the controller?

Paul
0
 
LVL 16

Author Comment

by:PaulCaswell
ID: 17913652
Perhaps I have been confused by some sample code I found. It assigns a controller for every person. Is this unusual or normal?

Paul
0
 
LVL 10

Expert Comment

by:jaggernat
ID: 17914920
>>>Who controls user interaction, the view or the controller?

The Controller . Controller is the boss :)

>>>how can the view tell the controller to scroll the window if it is independent of the controller

Each view (in MVC) has a unique "mapping" to the controller...meaning , for instance lets say there are three views
Parentview, Childview, Siblingview. Now all these three views call the controller in three different UNIQUE ways , so the controller knows WHO is making the call(parent, child or sibling).

 


 


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tomcat: Unable to run tomcat service. 2 28
eclipse buid path vs tomcat lib path 10 37
passing enum to a method 4 34
Coding for the first time 9 62
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question