3 ms·
I tend to find this dream rather fevered. A controller knows about the model. It knows about the view. It acts as a conduit between itself, the view and model.
by virmundi 14y ago
I tend to find this dream rather fevered. A controller knows about the model. It knows about the view. It acts as a conduit between itself, the view and model. In the web, the models are not really event based. Some platforms have tried this, but it tends to not work out well at scale. So ultimately the controller tends to get a lot of business logic embedded because it's difficult to put that logic somewhere else.
The problem with this is that the controllers are very much view-centric. Take .NET for example. There are forms. Logically this is the controller. Events happen, handlers manipulate domain objects and create responses, the result goes to the view. The problem is that even .NET makes a divide between WinForms and WebForms. Entirely different namespaces. Thus your controller is view bound and blocked.
Now you might want to push the logic from the controllers down into the domain objects. This is fine. But, as other talked about with testing, you will have to make sure that you're not doing too much with your domain objects. So you'll probably start to use interfaces and constructors for the domain objects to abstract away view details. You might even use callbacks (another type of interface).
So you're feeling pretty good now. But eventually this type of configuration become heavy. It also might not mesh with your system. I'm not sure about Rails, but Hibernate makes is rather hard to IoC objects it makes. It's really hard to do that by having Spring create your instance variables returned by Hibernate.
In the end, the difficulty of making domain objects smart and loosely coupled, but still coupled to other components while using an ORM makes the whole attempt for naught. Thus you will circle back and put the business logic in the controller or some controller adjacent code that is closely coupled with the view.
- mattgreenrocks 14y agoThe whole point of attempting this is to allow these difficulties to force you to decompose the system further than you would using the larger building blocks of MVC. About six months into working with Rails full time, I began wanting a third place for my logic. Controllers were suboptimal, and models weren't always right. Coming from a native apps, I felt restricted. I later learned that POROs were well and good. But I doubted myself because the Rails way says little.
- virmundi 14y agoI'm good with POROs (assuming Plain Old Ruby Objects). I'm a huge fan of Domain Driven Design. My issue with the parents is that without going into what many Rubyists would call Java-land, one would find it hard to separate concerns. Also, I don't agree that an MVC can truly be fully decoupled from the V. This is why one seldom has one MVC to rule them all.
- freework 14y agoTake a look at giotto, a python web framework that tries to do exactly what you're proposing: separation of model, view, and controller so that they are completely decoupled: https://github.com/priestc/giotto https://github.com/priestc/giotto