52 points · by karmajunkie · 14y ago · 21 comments
The way I've been thinking about it for myself is to imagine your Domain Objects as this 3D space of object relationships and interactions. So a Presenter cuts a 2D plane through that space and let's you view from a certain perspective.
In the case of Commands, you're taking a certain perspective and mutating that 3D space through it.
Not sure if that helps anyone else :-)
Also the focused_controller project looks really interesting as well. I was working on my own web framework, that made Actions first class objects as well. And since it was built on this slick IoC library, your Actions could just declare they need this Command, or these two Services to complete the request and they would automagically get them. I really like the idea of "one object(graph) to represent accomplishing a task", and then just having that object(graph) go do the work.
Complex logic interacts with complex object graphs, not individual models. Therefore, complex logic does not belong in models or controllers (or views). Complex logic belongs in instantated objects (not modules) that represent complex logic. This style may also be known as the "Strategy" Design Pattern.
Strategy objects can have state during their activities, this is why they should be instantiated.
Strategy objects simplify testing because they can be connected with any object graph that presents the same interfaces as the target object graphs.
This leads to interchangable Strategy objects that represent generic behavior which can be applied to actual, simulated or speculative object graphs.
Also check out the DDD/CQRS google group: http://groups.google.com/group/dddcqrs
MVC is a triangle, rails style frameworks are a line. This is called MVA (Model-View-Adapter). The "adapter" being in between the view and the model who can only interact with the adapter and not each other. The second issue is that in adapting MVC to the web, many frameworks continued with the "one controller per view" notion, despite that being done because of the limitations imposed when creating GUI apps. There is no need for multiple controllers in a web app, all input comes in the same way no matter what view the user is seeing. In fact, the user doesn't even need to be seeing a view, there is nothing tying a view to what actions are possible, you can always submit any http request you want. Your "routes" are your controller, there is no need for a second level of controllers on top of that.
The goal of MVC was to expose model functionality to the user directly so they could understand and work with the domain model clearly and easily. Controller meant "controls the input and output" not "controls the users experience". The guy who created MVC considers naked objects style frameworks to be the closest thing to MVC for the web, not rails style MVA frameworks.
And there is something very weird about this statement:
>On top of that, it’s very common to see logic pushed down into the model
Of course that is common, that is what is supposed to happen. Models are not "stupid containers to pretend to kinda represent my DB sorta but not really". Models are the business logic. Models are the actual application. You are modelling the domain, not modelling the database. The model is the domain, it is all the business logic. The view is the way we present information to the user. The controller is the part that handles input and output. Very simple and effective system, but very poorly understood and virtually never used any more.
I'm in 100% agreement WRT to MVC—Rails' idea of MVC was never really MVC as MVC was originally envisioned.
It's worth noting that as originally envisioned, the controller directly dealt with the keyboard and mouse. I would argue that not only is Rails not MVC as originally envisioned, something that reanimated the original controller would probably suck.
MVC as done in Cocoa on the other hand, is really good. Stock, reusable controllers that simply mediate communication between models and views. If any MVC-style web framework had something like this, it would be pretty amazing.