▲ | skydhash 4 days ago | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Controller is where your logic is. Your model is your state, and the view is presentation. Both are static. The controller is the dynamic aspect that update the view to match the state and update the state according to interaction or some other system events. Splitting the logic from the state and presentation make the code very testable. You can either have the state as input and you test your presentation, or have the presentation as input (interaction and lifecycle events) and test your state (or its reflection in the presentation). Also this decoupling makes everything more flexible. You can switch your presentation layer or alter the mechanism for state storage and retrieval (cache, sync) without touching your logic. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | mpweiher 4 days ago | parent | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> Controller is where your logic is. That's actually precisely the anti-pattern. Massive View Controller is an example of this. The Model is where your logic is. Everything that is in any way semantically relevant. Views handled display and editing (yes, also editing!). Controllers ... well ... I guess you might have a need for them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | js8 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
I always thought that business logic, expressed in the language of your domain, should be part of the model. The controller is just a translator from the language of keystrokes and mouseclicks into the domain language, and the view is just a translator from the domain language into pieces of text and widgets to display to the user. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | dsego 4 days ago | parent | prev [-] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
In the server-side web world the controller should ideally only receive http actions and call services or fat models. It should have no business logic, only validation and parsing. In the frontend UI world the controller is bound to UI events and communicates those from the view to the model objects. (1). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|