This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I'm new here and like the friendly feeling to this forum, so I thought I'd ask for a little help.
I'm creating a simple program with a GUI I've built using the NetBeans IDE.
I would like to understand some basic techniques for decoupling a UI from the objects which it's based upon. I've done some reading with regards to MVC, but much of what I've read seems aimed slightly above my level for the moment.
I have a simple class designed to calculate the linear expansion of a substance depending on what it is and the temperature range applied. Here's my class so far:
This page (flickr) shows my GUI I have so far. The application is working currently, but all the logic is contained in the form's class.
It looks like you already have your model and view pretty well established, so you just need to create a controller. Basically, the controller is the piece that "connects" the model and the view, passing messages back and forth as needed.
In setting up the controller, ask yourself: When something changes in the view, does the model need to know about it? And when something changes in the model, does the view need to be updated?
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Aug 06, 2008
Thanks. I'll give it a go...
Joined: Aug 06, 2008
There seems to be a fair amount of variability for how to achieve this. These two diagrams capture my thoughts so far:
The model appears to be unique to the view in most cases, but for my situation I would like any changes in the model to by automatically updated to any view which is representing it, whther using the same controller or not.
Actually, the link Marc provided was a great help, other than this point (unless I missed it).
And I understanding the concept of MVC correctly, or missing the point completely?