Solved

MVC with a twist.

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

789 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