wood burning stoves 2.0*
The moose likes OO, Patterns, UML and Refactoring and the fly likes mvc design problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "mvc design problem" Watch "mvc design problem" New topic
Author

mvc design problem

Stary Kapec
Ranch Hand

Joined: Dec 04, 2005
Posts: 81
I am writing an MVC application for making graphs.
My graph elements are designed in the MVC way either.
The state of a single node is distributed over view(position, selected,...)
and model(label, incoming/outcoming edges). All references between a node and
the other nodes, it is connected with, are kept in its model.

The problem I've encountered, is when I try to do some operations on edges
connected to some node. For example I want to delete a node... When a node is
to be deleted, all edges it is referring to are to be deleted too.

To delete a node from my application code I am using a reference to its
controller, from which I can retrieve only edge models. But to delete the edges
I must have references to their controllers too!

Should I have methods in the NodeController class returning EdgeControllers?
But it is not so easy. NodeController would have to create them based on its model,
but it doesn't have enough information to do that.

Thanks in advance.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I was following this until you got to the point where you seem to be describing multiple "controllers". This sounds a strange use of MVC to me. Can you describe the purpose and use of these separate controllers in a bit more detail?

I'm guessing that if I were implementing this I would have one or more UIs collaborating with a single model for the whole graph and a single controller for the whole graph. The single controller also collaborates with the model to make its changes, and the single model is presumably comprised of a collection of sub models representing nodes, edges, faces, or other components of the graph.

To remove a node, the UI tells the controller, which finds the node, gets all its edges and the nodes at the ends of them, tells each end node to drop the edge in question, then drops the newly unconnected node. The UI(s) can then be updated beased on the new model.

Does that make sense?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Stary Kapec
Ranch Hand

Joined: Dec 04, 2005
Posts: 81
Is that mean there should be only one view of the graph?

...and the single model is presumably comprised of a collection of sub models representing nodes, edges, faces, or other components of the graph.


Lets say the graph view would also be compound of many sub views.
How then map these sub models to its correspondent views having only one graph controller?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Jasiek Motyka:
To delete a node from my application code I am using a reference to its
controller


A controller should only be responsible for interpreting user gestures. The actual deleting should happen in the model. If some of your business needs to delete a node, it shouldn't use a controller to do so. In fact, it shouldn't even know about the existence of controllers.


from which I can retrieve only edge models. But to delete the edges
I must have references to their controllers too!


I think you misunderstand how MVC is supposed to work.

If a user deletes a node, the controller should simply tell the model to delete that one node. It is then the responsibility of the model to find out about the edges that need to be deleted, too - as this is business logic, not presentation logic. That is, what edges will be deleted doesn't depend on how the edges are presented (view) or how the user interacts with them (controller).

Once the model deletes an edge in the model, the model notifies all of its observers that the edge got deleted. One of the observers will be the associated view, which then takes appropriate action to update the UI.

Does that help?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mvc design problem
 
Similar Threads
Undirected graph help - using ArrayLists and Maps.
problem in validation during deleting a record from DB
JTee
JTree Porblem ! Pl help!
JTable deleting a row memory problem