The best practices I've seen for MVC apps isn't to put all the logic in the controllers. What you do is to create a "services" or "managers" layer that is called on by the controllers. A userService, for example, might have a function user = userService.login(name, password) It's also nice to abstract this service layer with some clean interfaces so that you can replace the underlying implementation, for example to m…
I agree, I really like the "services" layer. I used it for years programming with Java/Spring and missed a lot when learning RoR. I think it is no coincidence that the two RoR real-world projects that I worked had enormous controllers. The service layer is great to orchestrate operations between models and I don´t know a reason for not using it.
MVC is dead, it's time to MOVE on
121–130 of 233 posts
Re: MVC is dead, it's time to MOVE on
#122And that wouldn't happen to have anything to do with the fact that "you" either don't know any other patterns or solutions besides MVC, or are under the impression that using MVC somehow forbids you to use other patterns?
Not to mention the fact that the definition of MVC that the author uses is false (in a way that describes MVC as more simplistic and limited than it truly is), but after so many years I'm not even going to argue with that any more. Just fucking Google it.
tl;dr: Those who cannot learn from history are doomed to repeat it.
Re: MVC is dead, it's time to MOVE on
#123I cant understand the distinction between a 'setter' (stated here as part of the MOVE 'model') and 'functions that let you save... to a database or upload... to an external API' (stated here as part of the MOVE 'operations').
I would understand the logic a lot more if the 'model' excluded 'setters' entirely and just included 'queries' (which don't change the underlying data set) as opposed to 'commands'/'setters' (which do...). As it is I'm not sure where the line is between 'operations' and 'model' except for the use-cases that have been explicitly stated.
Re: MVC is dead, it's time to MOVE on
#124Earlier quoted context omitted.
JSON and RSS views don't make sense - in MVC, views are visual representations of data (the model). Views are how the user percieves the application. JSON and RSS are just different methods for representing data to be communicated to other systems.
So it's only a view when you write all your code to push bits to the monitor yourself. Outputting using libraries that convert formats like html (-> browser -> os/driver -> screen) aren't views. Got it.
Re: MVC is dead, it's time to MOVE on
#125Re: MVC is dead, it's time to MOVE on
#126Re: MVC is dead, it's time to MOVE on
#127Re: MVC is dead, it's time to MOVE on
#128Earlier quoted context omitted.
In the context of MVC, a user is a human being - describing JSON and RSS services as "views" totally misses the point. Quote from the inventor of MVC, Trygve Reenskaug: "The essential purpose of MVC is to bridge the gap between the human user's mental model and the digital model that exists in the computer."
I'm a human user and I have a mental model of the json and rss apis I consume via code I write. I notice that he didn't say visual as you did earlier
Source: http://heim.ifi.uio.no/~trygver/1979/mvc-2/1979-12-MVC.pdf
And you are not a human user, you are an engineer.
Re: MVC is dead, it's time to MOVE on
#129The biggest problems I've seen in model 2 architectures is weak models. The side effect of this is everything gets stuffed in the controllers. This is understandable because there is no observer pattern and therefore the models don't have nearly the power they do in real MVC.
Heres a great explanation of the MVC[1]:
In a nutshell the classic MVC architecture work like this. There is a model that is at the heart of the whole thing. If the model changes, it notifies its observers that a change occurred. The view is the stuff you can see and the view observes the model. When the view is notified that the model has changed, the view changes its appearance. The user can interact with the view (e.g. clicking stuff) but the view doesn’t know what to do. So the view tells the controller what the user did and assumes the controller knows what to do. The controller appropriately changes the model. And around and around it goes.
[1] http://michaux.ca/articles/mvc-architecture-for-javascript-a...
Re: MVC is dead, it's time to MOVE on
#130Earlier quoted context omitted.
So it's only a view when you write all your code to push bits to the monitor yourself. Outputting using libraries that convert formats like html (-> browser -> os/driver -> screen) aren't views. Got it.
Let me give you an example. In your model, you have represented the salary of an employee as an integer. In a web application, the salary can be presented to the user through numerous different views - as a number on the screen (plain HTML), as a slider (jQuery UI slider), as a bar in a bar chart (using some charting library). The tools you use to build the view are not relevant.
as JSON encoded output, as XML....