Solved

MVC with a twist.

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

708 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now