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

Shane van Wyk
  • 1,870
  • 1
  • 26
  • 62
  • I suppose using observer will decouple the classes a bit so more expandability and less reliability – Shane van Wyk Aug 28 '11 at 12:13
  • 1
    You should definitely separate model/view, but separating view/controller can be tricky. You can read [here](http://java.sun.com/products/jfc/tsc/articles/architecture/#roots) that even Swing itself is not really MVC. – toto2 Aug 28 '11 at 12:30
  • Thanx For that will have a read, looks good :) – Shane van Wyk Aug 28 '11 at 12:31

2 Answers2

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.

Pavel 'PK' Kaminsky
  • 796
  • 1
  • 10
  • 22
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!)

  • 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 – Shane van Wyk Aug 28 '11 at 12:37