• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

mvc design problem

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Stary Kapec
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic