What are your favourite patterns for writing a controller?
你最喜欢的编写控制器的模式是什么?
1 个解决方案
#1
3
This is rather a tough question as MVC is applied differently in different contexts. For example, for a desktop GUI, you might have listeners for event notifications of view changes but such behavior typically isn't used for Web forms (AJAX is changing this).
这是一个相当棘手的问题,因为MVC在不同的环境中应用不同。例如,对于桌面GUI,您可能具有视图更改事件通知的侦听器,但此类行为通常不用于Web表单(AJAX正在更改此设置)。
For the Web, you generally have:
对于Web,您通常具有:
- Model: business logic
- View: presentation logic
- Controller: application logic
模型:业务逻辑
查看:表示逻辑
控制器:应用逻辑
The controller should generally be minimalistic and if you find yourself pushing display information or business rules in it, there's probably a design flaw somewhere. Classic examples of such flaws in the controller are building HTML (view) or accessing the database directly (model).
控制器通常应该是简约的,如果你发现自己在推动显示信息或业务规则,那么某个地方可能存在设计缺陷。控制器中此类缺陷的典型示例是构建HTML(视图)或直接访问数据库(模型)。
I've written up a more thorough description of MVC on my O'Reilly blog. I have concrete examples there which can help explain things a bit more in depth.
我在O'Reilly博客上写了一篇关于MVC的更全面的描述。我在那里有具体的例子可以帮助更深入地解释事情。
#1
3
This is rather a tough question as MVC is applied differently in different contexts. For example, for a desktop GUI, you might have listeners for event notifications of view changes but such behavior typically isn't used for Web forms (AJAX is changing this).
这是一个相当棘手的问题,因为MVC在不同的环境中应用不同。例如,对于桌面GUI,您可能具有视图更改事件通知的侦听器,但此类行为通常不用于Web表单(AJAX正在更改此设置)。
For the Web, you generally have:
对于Web,您通常具有:
- Model: business logic
- View: presentation logic
- Controller: application logic
模型:业务逻辑
查看:表示逻辑
控制器:应用逻辑
The controller should generally be minimalistic and if you find yourself pushing display information or business rules in it, there's probably a design flaw somewhere. Classic examples of such flaws in the controller are building HTML (view) or accessing the database directly (model).
控制器通常应该是简约的,如果你发现自己在推动显示信息或业务规则,那么某个地方可能存在设计缺陷。控制器中此类缺陷的典型示例是构建HTML(视图)或直接访问数据库(模型)。
I've written up a more thorough description of MVC on my O'Reilly blog. I have concrete examples there which can help explain things a bit more in depth.
我在O'Reilly博客上写了一篇关于MVC的更全面的描述。我在那里有具体的例子可以帮助更深入地解释事情。