Solved

MVC with a twist.

Posted on 2006-11-09
4
384 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JUnit 4 @Before and @BeforeClass differences 3 60
github account with ecipse 1 48
jar file executable 12 52
couple of eclipse 5 38
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

832 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