2

Still wondering the best way to do Model-View-Controller Software Architecture, Do I pass the Controller into the View, or do I use the Observer Design Pattern and let the Controller Observe any changes/requests made by the view so we can update the model and redisplay that.......

I have A Main JFrame which will have JInternalframes, and i want to apply the MVC Architecture. Using just a normal Java Application

Kind of stuck on this any suggestions to limitations ect will help a lot.

Sorry For the confusion, didn't there was an web aspect that just uses Frame and Internal Frame

3
  • I suppose using observer will decouple the classes a bit so more expandability and less reliability Aug 28, 2011 at 12:13
  • 1
    You should definitely separate model/view, but separating view/controller can be tricky. You can read here that even Swing itself is not really MVC.
    – toto2
    Aug 28, 2011 at 12:30
  • Thanx For that will have a read, looks good :) Aug 28, 2011 at 12:31

2 Answers 2

1

I have written a program with the MVC pattern last year but I can't seem to find the code atm, I DO recall that I used it with the observer pattern, so that the Controller listened to the View (so controller implements Observer, view implements Observable)

(note: I'm still a student so there may be some errors in my comments.. just trying to help though!)

1
  • Algood that is pretty much how i have it and what my understanding is of it haha. Thanx for your input :) Someone in my degree also one of my mates suggested using the Observer Pattern + MVC as you Decouple your code a bit making classes less dependant on each other and more flexible Aug 28, 2011 at 12:37
1

Your Mainframe contains all the frames, therefore they are accessible to it. The internal frames should get their "father" frame in the constructor as a a parameter, and store it as a context variable.

That way you can use both: if you decide to pass controller (MainFrame), views (InternalFrames) can register on its event, or you can update view through your controller.

regarding your question , you should use the Observer Design Pattern. this is logically correct to let the Controller control the flow and update the view upon model change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.