▲ | mpweiher 4 days ago | ||||||||||||||||||||||||||||||||||
> The model itself and the view of the model (and the user’s mind). Trygve was very explicit about the model being a model of how the user thinks about the problem: There should be a one-to-one correspondence between the model and its parts on the one hand, and the represented world as perceived by the owner of the model on the other hand. https://web.archive.org/web/20090424042645/http://heim.ifi.u... Second paragraph. > There has to be a boundary that controls changes to the model. Yes. It's called the API of the model. The model makes available API for all semantically valid operations. As I wrote elsewhere, I usually have a facade that acts as the top-level API for the model. The views can call this API. So can other entities. > The controller ... decides what view to show possibly. But views can handle their own subview. > The controller ... and retrieves model data to project Nope. Not the job of the controller. > The controller ... and translates change events coming from the external world (views or events) into changes the model should interpret. Nope, it doesn't. The views typically do that as well. Controllers may be get involved if there is a complex sequence of steps that doesn't really naturally fit into a view. > That’s a lot for one class so it can get confusing very quickly. Yeah, if you put all sorts of stuff in the controller that doesn't belong there. > Why localize it in one place? Indeed. Don't incorrectly localize all these things in one place. MVC, for example, tells you not to do this. > This all works but three years later it’s hard to figure out when I read the code again. Yes. MVC is much better than that thing you came up with. | |||||||||||||||||||||||||||||||||||
▲ | sunir 3 days ago | parent [-] | ||||||||||||||||||||||||||||||||||
That’s a fair critique. Though the snark was unnecessary. I took the time to reread the literature and review my actual code. My updated understanding. Model controls and holds the state of the system. It ensures the data is always valid. Controller controls the boundary between the system and the user. View represent the model and capture user intent to change the model. They ask the model for data they need; however I disagree with the practice that views change data directly but instead prefer they send an intention to change to the app which does the work. Auth was not considered in 1979 as far as I can tell. Authentication is part of the “controller” but in middleware usually because it’s part of the user input boundary, and generally better if done in one place early in the event lifecycle. Authorization is part of the model. App logic is decomposed into workflows or use cases in the app layer. Events coming in through the controller are translated into what the system understands and then passes it onto the workflow to execute. Thus these should take change intent from the view and then actually tell/ask the model what needs to change. This allows the app to catch errors from the model, recover if they can, or handle multi step flows. Results and errors are then sent back to the view (eg GUI dialog) or controller (eg api call) that initiated the workflow. This makes it easier to put different views over the same app logic (mobile, web, api, agent) and also test workflows in isolation. Modern views have their own controllers for mouse and keyboard. That’s fine. Don’t care. That’s effectively outside the system in the client experience (eg browser) anyway. Where I have trouble is when I - put a ton of app logic in the controller - put a ton of model updates in the view - have a single controller for the entire system instead of one per system boundary/interface of user events. The (DDD?) style of app logic being encapsulated outside of the controller makes a lot more sense to me now that I see it. | |||||||||||||||||||||||||||||||||||
|