I have a simple java gui calculator, with 3 number systems (there are some bugs but that doesn’t matter now). Currently all code is in one file. My task is to rewrite it as MVC, and add possibility to run it in either gui or console mode. How should I divide this program to organise it as M-V-C ? Is it written properly enough to add console functionality to it? (guess I’ll have to change all methods invoking to JLabel Output to something simply storing an output String as a model argument and then having View to get it).
Here’s the starting code :
http://paste.pocoo.org/show/224566/
Here’s what I already have :
Main :
http://paste.pocoo.org/show/224567/
Model :
http://paste.pocoo.org/show/224570/
View :
http://paste.pocoo.org/show/224569/
Controller :
http://paste.pocoo.org/show/224568/
I don’t have view in my model so I can’t call to Output. That’s the first problem I can see.
The current separation looks good. Here are some pointers for implementing the console view:
Actionclass. The view then invokes the action in response to UI gestures. This keeps the controller independent of the view implementation, and allows the same controller to be used by multiple views.The Console View can then read standard input, and write status to standard output by querying the model, and invoke functions using the Actions exposed by the controller.
A good test of MVC is creating two views on the same model and controller – both should work correctly and update from changes from the other.