In the ObjectWeenie shop I used to work in, ModelViewController was a sacred concept. They would have considered AllenHolub's point of view blasphemy: Model-View-Controller is not Object-Oriented.
See article http://www.javaworld.com/javaworld/jw-07-1999/jw-07-toolbox.html
The gist of it is that things that should be single objects with information-hiding opaque innards instead become transparent and spread over each of Model, View, and Controller.
Ok, it's interesting, but that's also the typical beginner error of Object design. I agree that this would be ideal to have each object know to do itself everything you want to do with it, print, jumpThroughNetwork, showOnMonitor, and so on. In practice, with object design, you end with objects that have each billion of services and know thousands of layers. That's very tough to manage at any level including for reuse and maintenance purpose. Interaction between those sort of objects would be cool but their internal garbage would be a nightmare. -- BernardDevaux?
So you're saying that you agree with Holub that MVC isn't OO, but that just shows he's an OO newbie, because everyone knows that it would be a nightmare to do an OO version of MVC???
I think that the article seems to complain about naive MVC designs that he's seen "in the trenches." When we talk about MVC, we're talking about turning everything into an event emitter, passing to a stream that aggregates upwards. When the author says that MVC is a poor application design, he is partially correct, because the "Controller" when interpreted as one "object" (which, for the record, he defines by capability) ends up with way (way) too much responsibility, thus breaking whatever tenets of OO you happen to be supporting today.
Big surprise, it's usually bad design. MVC is not especially un-OO in the context it's supposed to be used in. It's called a PatternMisapplication? and it's just bad design decision. You don't blame a pattern for being misused. Perhaps you should rename this page MVCIsAPoorApplicationPattern or something a little less misleading? -- DaveFayram
No, because Holub does make the claim that MVC isn't OO, thus the page name is perfectly on target for his claim, despite the fact that you have a rebuttal. Changing the title would be tantamount to DisagreeingByDeleting. But if you think that there's room for discussion of further issues under that other name, well then, by all means...
It does sound like you have more to say on that topic that would be interesting to hear.
I personally am not ready to take sides on Holub's claim, because although I've been hearing about MVC for years and years and years, every time I think I completely understand the subject, I hear someone claim things about the topic that make me wonder all over again. I'm beginning to think that MVC is like OO itself: many people have many different definitions, including multiple interpretations of what the original MVC was all about.
Earlier today someone said that UI is just a subset of MVC, whereas I would have thought that MVC was a subset of UI, despite the fact that MVC has been applied to non-UI domains, and clearly (?) originally was only about UI...wasn't it?. But what do I know.
I used to know Holub personally, a long time ago, and I thought he was a smart guy who knew lots about lots, but I don't happen to know his OO background in particular, so I can't confirm or deny whether he's an OO newbie.
Well, I won't pretend to understand the implied social implications of renaming this page. :) I read the rest of his paper, and his design seems to make sense from a very limited point of view. However, his solution of instead inverting the relationship and saying to objects, "Instead of me drawing you, you draw yourself on me." isn't really a solution. You still have a dependency. In the case of ATMs (as in the article), ATM hardware is hard to upgrade, so making software that assumes that the requirements may change but the software will not is reasonable. The way MVC works best, in that it gives the most payoff, is when you have a whole lot of good abstractions to build on, then build more.
When a GUI button gets pressed, conceptually what we want is for an event to be emitted. When a model changes, we want an event to be emitted. The controller then serves as a translator to coordinate these events together. These events can contain heavy abstraction, so that when one component changes the events are already prepared to handle it. If you actually make your code actually do that (as opposed to saying methods firing are events like, say, QtDesigner would), then MVC will go a lot further and perform better as an application pattern.
What I'm describing is basically what the PragmaticProgrammer talks about, so I don't think I'm too far out on a limb here. -- DaveFayram
Here's another thought: is Holub basically just talking about applying LawOfDemeter to MVC?
I think the way MVC is implemented in J2EE applications using JSP is not very OO. You are placing your data in objects called Beans that represent the View layer and have no logic and are therefore nothing but data structures. All of your logic goes into the part that is usually considered the Model layer, but there is more logic in the Controller layer, so people get confused about what belongs in the controller layer and what belongs in the model. But to me, the idea of separating data from code and putting it into dumb data structures is not very OO. -- WillCardwell
I believe that the above is a simple statement of fact. MVC is a procedural decomposition. The Model contains persistent data access functions. The View contains user interface functions. The Controller is less well defined, except as "glue" between Models and Views.
one of holub's claims is that multiple views for a model is never done outside of excel. apparently he's never had to render graphs and charts (e.g. work on any kind of financial instrument pricing package and give the end user only one view of the model and watch how many heads roll).
furthermore, data entry/editing is merely a different view than data rendering.
I found holub's article to completely miss the mark of MVC in general... furthermore, I think his concept for the atm model would yield very heavy-weight objects (something I personally dislike).
Now, if he were to say "an object should have one rendering, and that rendering is xml, and a view could render that xml however it darn well pleased" I might amend my thinking. ;)
Holub's completely off the mark. Starting from the false premise that you write a completely new view for every completely new model he arrives at a bogus conclusion. In reality, models are composed and views are composed. The protocol between them also composes in some way. You don't create views that poke around in the innards of models, instead you create factories that build composite models and matching composite views and then seal up the details.
On a more practical note, Holub advocates "direct display", which wires the display logic into every model. MVC allows to provide a new view for an existing model (compare old HTML 2, which could be displayed on a computer, a cell phone, a printer or could be converted to speech), "direct display" destroys that (compare modern HTML "optimized for $BIG_BROWSER", which has to be reinvented as WML to display on cell phones).
It should be noted that, whether MvcIsNotObjectOriented or not, inherently, it obviously is true that MVC has been done in a non-OO fashion (or in a poor-OO-practices fashion) many times by many projects. That fact (I do think it is a fact) should ideally be addressed in pro/con arguments here: MVC done right is OO/not-OO because...<whatever>, whereas MVC done wrong is not OO because...<whatever2>
MVC might actually be an abstraction of the OO paradigm. The Model is the same as an Objects state. The View is the same as the Objects interface, and the Controller is the same as the Objects implementation. So, in a way, OO and MVC are just presentations of the same idea. Now, if only Java had better meta-information support, building a gui would be as easy as designing an object :-)
I agree that the Model is the object's state (instance variables), but I think the View would actually be its accessor methods, and the Controller would be its mutator methods.
(Moved artical reference to ArgumentsAgainstOop)
See AllocationOfResponsibility.
I agree that getters and setters 'are evil' but I dont agree that the MVC pattern has to use straightforward getters and setters - i.e. things that read the model data and set the model data directly. Houlob says himself that there are situations where you have to ask an object for data - in some form or the other - and thats what the View should be asking of the Model: Not for its internal data, which it isnt interested in, but for a UI-compatible version of that data. That way when you change the internal representation of anything, you arent breakng the View 'getter' because the typethe view is interested in shouldnt change - lets say a String: it doesnt care if thats stored as an int, String, Float or composite in the model itself. Similarly, the controller shouldnt call a setter on the model - it should send it a request that may cause the model to changes an attribute or perform some procedure, according to the models own internal logic.
Houlub has gone one step further, however, and instead of just passing off data to the view in a form that is view compatible, he also gives his 'visual-proxy' the responsibility of drawing that data as well, which is the thing that has people up in arms for all the reasons listed above.
Lastly the multiple view thing where you have a pie chart or a line chart is a bit of a straw man by houlub. That might not be very common, but what is very common is composing screens that use various attribues from many model objects, and I thnk thats another area that people are shooting down the visual proxy idea.
The statement that MVC is not object-oriented stemmed from the lack of such languages as Java or C# when the article was written. Consider the recent work by R. Pawson's group on the 'Naked objects' implementation (both for Java-JVM and for CLR on Windows). Even though some people tend to put 'Naked objects' at the same level as MVC, this is wrong just because the 'Naked objects' is the consistent approach to implemnting the MVC paradigm. Actually, in 'Naked objects' you do not need to implement the View portion of MVC; it is done by the framework for you. The quality of your implementation depends on the level of understanding the problem and the ability to decompose it to the right set of business objects and their interactions. So, I would not state that MVC is not OO by any means even though it has non-object oriented implementations (for languages and environments that existed before OO came to play).
R Pawson adds: FYI In the most recent implementation of Naked Objects for .NET - known as 'Naked Objects MVC' - we've actually made the relationship between the Naked Objects pattern and the MVC pattern both clearer and more explicit. You can write Model objects and get a complete web UI for free without writing any Views or Controllers, just by using the generic, reflective, Views and Controllers. But you can then go on to write bespoke views to customise the presentation and/or bespoke controllers to customise the flow of the application. This gives you the best of both worlds. We cannot prevent people from putting domain logic in their bespoke Views/Controllers (which happens a lot in normal MVC in my experience) but the fact that you don't need to write any Views/Controllers to get going is a good way to encourage developers to put the domain logic where it belongs - encapsulated on the objects. TrygveReenskaug (who was the external examiner for my PhD thesis on Naked Objects) has said that it was the intention (of his group at Parc in the late '70s) to implement something like this, but they never got it done.
"Houlob says himself that there are situations where you have to ask an object for data ... the View should be asking of the Model: Not for its internal data .. but for a UI-compatible version of that data"
- A UI-compatible version of the data is more commonly referred to as a ViewModel?, is it not? So it appears using MVC without a VM is doing it wrong - with no abstraction between the data of the model and the data used by the view, there is a violation of encapsulation and hence not OO.