Page 1 of 1
MVC dependencies
Posted: Sun Feb 04, 2007 1:09 pm
by alex.barylski
Am I wrong or does MVC have different dependencies when developing in an event based environment as opposed to a request/repsonse?
While tinkering with Zend I have noticed that I can successfully keep dependencies out of the View and the Model having the controller manage both. Yet I am sure I have read articles where they suggest otherwise...
Event based development, like Windows applications:
1) User clicks button
2) Controller updates the Model
3) Model notifies the Controller of changed state
4) Controller notifies View
5) View pulls on Model
I have seen a few articles which "suggest" optional dependencies between each component of the triad...when really...I fail to see why the Controller can't simply handle dependencies - as it's basically the wiring that pulls the Model and View togather anyways.
When building a web based applications using Zend...when would the view ever need knowledge of the model...the way my code is currently setup...the controller pulls on the model and passes that data to the view...or simply just pulls on the view or the model...
Model and View have zero knowledge of each other...dependencies are centralized in the controller and I can't complain - despite my possibly doing something against traditional accepted MVC practices...
Comments?
Posted: Sun Feb 04, 2007 3:50 pm
by Chris Corbyn
Yeah it's a bit different. I've had to rewire my brain when doing Java/AWT stuff. I treat event handling as Controller since that's what you're doing by dealing with events. Model can be a bit weird with a language like Java since sometimes it encompasses bits and pieces which directly relate to the view and your Controller (aka event handling layer) makes changes in Model which purely change the View.
I can't speak for windows specific code but with Java I've adopted this approach:
Application entry point class == Front Controller
Front controller run's it's main() method and creates an instance of GUIModel, an instance of GUIController is then created and is passed the model. The controller is then given a new instance of GUIView, at which point it attaches listeners to various components in the View (this is the bit that feels odd) and gives it a reference to Model. The rest is obvious... events fire, GUIController listens (or classes aggregated in it do) model changes, View is redrawn (which of course reads the changes Model).
I always thought request-response was much clearer cut but my brain is gradually starting to fathom it out. I still haven't quite grasped it completely... if I "feel" like somethings in thw wrong place, it probably is
EDIT | I should point out that's just a scheme for the overall app. Each component may implement it's own smaller MVC environment since something like a date picker, although it's just a widget/component in the GUI listens for specific events, update a specific model and has a specific view.
Posted: Mon Feb 05, 2007 1:29 am
by alex.barylski
d11wtq wrote:Yeah it's a bit different. I've had to rewire my brain when doing Java/AWT stuff. I treat event handling as Controller since that's what you're doing by dealing with events. Model can be a bit weird with a language like Java since sometimes it encompasses bits and pieces which directly relate to the view and your Controller (aka event handling layer) makes changes in Model which purely change the View.
I can't speak for windows specific code but with Java I've adopted this approach:
Application entry point class == Front Controller
Front controller run's it's main() method and creates an instance of GUIModel, an instance of GUIController is then created and is passed the model. The controller is then given a new instance of GUIView, at which point it attaches listeners to various components in the View (this is the bit that feels odd) and gives it a reference to Model. The rest is obvious... events fire, GUIController listens (or classes aggregated in it do) model changes, View is redrawn (which of course reads the changes Model).
I always thought request-response was much clearer cut but my brain is gradually starting to fathom it out. I still haven't quite grasped it completely... if I "feel" like somethings in thw wrong place, it probably is
EDIT | I should point out that's just a scheme for the overall app. Each component may implement it's own smaller MVC environment since something like a date picker, although it's just a widget/component in the GUI listens for specific events, update a specific model and has a specific view.
1. Thats pretty much my understanding...
I figure that main() is analogous to PHP libraries like Zend or Symphony run()
2. MVC is a complicated pattern...no dought...that and the fact there are so many different takes on it it's almost mind boggling...I have failed to find a solid concrete definition...and believe me I have searched high and dry into the deepest bowels of Google as well.

It's a scary place
I think part of the problem is the paradigm shift...going from desktop to web based...requires a totally different mind/skill set...I figure thats why this thread has enjoyed such little attention from a community that otherwise loves design pattern disscussion
It's one thing to program in Java...but it's entirely different to program in Java using one of the GUI frameworks...I'm actually not at all familiar with Swing (except what I have read of your posts - gaining interest thanks to you) but I am experienced with C++ frameworks...and I can see there are many similarities - minus the hassle of working with C++ cryptic syntax and pointer hell, etc...
Taking this off topic...how have you found the Java experience thus far? It certainly seems the community is more geared towards architectural design than C++. CPP Programmers have a tendancy to pride themselves on writing fast, efficient code as opposed to solid, maintainable code using design patterns, etc. That is something I have struggled with myself.
I find Java applications so sluggish on my computer...it's why I haven't bothered making the switch...that...and I pretty much enjoy PHP exclusively now
Anyways, thanks for the feedback...
Cheers

Posted: Mon Feb 05, 2007 11:56 am
by Chris Corbyn
I'm really enjoying Java. I'd almost go so far as to say I'm enjoying it more than I enjoy PHP at the moment. It just feels so cleanly structured. To be honest, apart from stricter syntax, if you can develop in PHP5 in an entirely OO sense then Java will feel quite natural.