- 浏览: 198514 次
文章分类
- 全部博客 (185)
- A Design Patterns (2)
- B Refactoring (0)
- C Test (2)
- D Software Engineering (0)
- E Other Tech Articles (4)
- F My Blog (0)
- G TechJie forum & QQ group (2)
- H Programmer (6)
- I 杂7杂8 (4)
- J Translations (0)
- [网站分类]1.首页原创精华.NET区(包含架构设计、设计模式)(对首页文章的要求:原创、高质量、经过认真思考并精心写作) (3)
- [网站分类]2..NET新手区(用于发表不合适发表在首页的.NET技术文章,包括小经验、小技巧) (14)
- [网站分类]3.非技术区(技术之外的文章,但不要涉及任何政治内容) (40)
- [网站分类]4.其他技术区 (9)
- [网站分类]5.企业信息化 (0)
- [网站分类]6.读书心得区(技术书籍阅读心得、书籍推荐) (8)
- [网站分类]7.提问区(.NET技术方面的提问) (6)
- [网站分类]8.技术转载区(.NET技术文章转载, 请注明原文出处) (24)
- [网站分类]9.求职招聘区(个人求职、企业招聘) (0)
- [网站分类]GIS技术 (0)
- [网站分类]SharePoint (0)
- [网站分类]博客园.NET俱乐部(俱乐部组织与活动方面的文章) (2)
- [网站分类]软件发布区(发布自己开发的代码、软件) (0)
- [网站分类]网站管理区(网站管理方面的疑问、建议、意见, 寻求管理员帮助) (0)
- [网站分类]业界新闻 (6)
最新评论
-
没有终点:
不懂 lz说的是啥 我太菜了
超简单SVN教程 -
韩悠悠:
超简单SVN教程 -
DraculaW:
orz...如果让他去写书很好奇这个作者会怎么解释vector ...
又见热书讨论《JavaScript征途》 -
gigix:
weiqingfei 写道为什么国内写书的都是烂人?
为什么高 ...
又见热书讨论《JavaScript征途》 -
weiqingfei:
为什么国内写书的都是烂人?为什么高手都不写书?
又见热书讨论《JavaScript征途》
Supervising Controller - Martin's "GUI Architectures" series (2)
zz from www.martinfowler.com
To be translated...
Supervising Controller
Factor the UI into a view and controller where the view handles simple mapping to the underlying model and the the controller handles input response and complex view logic.
[TBD: Not sure yet whether to use the word 'controller' or 'presenter' here.]
Many UI frameworks provide the ability to easily map between the view and model, often using some kind of Data Binding. These approaches are very effective in allowing you to declaratively set up a relationship between elements in the view and model. Usually, however, there are more complex relationships which require you to have more complex view logic. This logic can be hard to manage, and in particular hard to test, while embedded in the view.
Supervising Controller uses a controller both to handle input response but also to manipulate the view to handle more complex view logic. It leaves simple view behavior to the declarative system, intervening only when effects are needed that are beyond what can be achieved declaratively.
How it Works
Supervising Controller decomposes presentation functionality into two parts: a controller (often called presenter) and view. The domain data that needs to be displayed is separate, and following rough MVC terminology I'll refer to it as a model, although it need not be a Domain Model. The basic division of responsibilities echoes the Model-View-Presenter architecture in its Dolphin form, as described by Bower and McGlashan.
A Supervising Controller has two primary responsibilities: input response and partial view/model synchronization.
For input response the controller operates in the presenter style. The user gestures are handled initially by the screen widgets, however all they do in response is to hand these events off to the presenter, which handles all further logic.
For view/model synchronization the controller defers as much of this as reasonable to the view. The view typically uses some form of Data Binding to populate much of the information for its fields. Where Data Binding isn't up to more complex interactions then the controller steps in.
Figure 1: Class diagram for the assessment example.
Figure 2: Sequence diagram showing the response for putting in a low actual value.
In the assessment window, the initial text change is handled by the text field widget in the view. This widget is observed by the controller, so when the text changes the widgets emits an event which results in the controller's actualFieldChanged
method being called. This method then handles the full response to the event. It first updates the reading model object's actual value. The window observes the reading object so the change to the reading's value triggers a refresh. It's pretty easy to map the actual and variance text fields' text to the appropriate properties of the reading, so that updates those values. For the purposes of our example changing the color is a bit more involved. The reading object can, and should, determine which category the reading should fit into. A sophisticated widget might be able to bind its text color to a category like this, but we'll assume we don't have such a clever young thing. In this case controller takes over setting the variance field's text color directly.
As the example shows, the essence of a good Supervising Controller is to do as little as possible. Let the view handle as much as possible and only step in when there's more complex logic involved.
One of the prime reasons to use Supervising Controller is for testability. Assuming the view is hard to test, by moving any complex logic into the controller, we put the logic in a place that's easier to test. In order to run tests on the controller, however, we do need some form of view, so a Test Double is often in order. With the double in place, we don't have any need for UI framework objects in order to test the more awkward parts of the UI behavior.
This testability issue affects another decision - whether the controller should access the view and its widgets directly, or through an intermediary. With an intermediary we build a Gateway for the the controller. The gateway defines an interface for the controller to manipulate. One implementation then adapts the window's interface while the other provides a stub for testing (you could also use a mock). This is the same approach that you need for Passive View.
Figure 3: Using an intermediary between the controller and the window.
The discussion so far suggests using Flow Synchronization with Supervising Controller, but this need not be the case. It is possible to use Observer Synchronization, but it needs to be modified so that it's the controllers that observe the model rather than the views.
When to use it
There are two main reasons to look into using a Supervising Controller: to separate out the complexity of an Autonomous View, and to improve testability.
The separation advantage is that it pulls all the behavioral complexity away from the basic window itself, making it easier to understand. This advantage is offset by the fact that the controller is still closely coupled to its screen, needing a pretty intimate knowledge of the details of the screen. In which case there is a real question mark over whether it's worth the effort of making it a separate object.
The testability reason is the more compelling one. Many people I've talked to have found using some form of controller has made a big difference to making a UI that is properly testable.
If testability is your driver then the driving issue is how much behavior to leave in the view. Passive View is a very similar pattern to Supervising Controller, but with the difference that Passive View puts all the view update behavior in the controller, including simple cases. This results in extra programming, but does mean that all the presentation behavior is testable. The choice between the two depends on what kind of Data Binding support you have and whether you're happy to leave that untested by controller tests.
A third alternative is Presentation Model. This again pulls most behavior away from the view, but leaves it to the view to synchronize all its updates. There isn't a great deal of the difference in test coverage between Presentation Model and Supervising Controller - much of the choice (as with Passive View) depends on personal judgments.
Significant Revisions
19 Jun 06: First publication in development area of website.
发表评论
-
Rhino Mocks To The Rescure
2006-11-23 09:17 791http://developernotes.com/archi ... -
Some high level concepts
2006-11-23 09:25 954http://structuremap.sourceforge ... -
Singletons Are Evil
2006-11-23 09:56 822http://c2.com/cgi/wiki?Singleto ... -
Best and Worst Practices for Mock Objects
2006-11-23 10:00 769http://codebetter.com/blogs/jer ... -
小函数:让你的函数变短的九个好处
2006-12-04 22:15 1130Small Methods: Nine Benefits ... -
UML序列图(zz)
2007-03-19 11:28 1282级别: 初级 Donald BellIBM 2005 年 2 ... -
重写方法不被认为是在类上声明的
2007-03-22 14:54 557当在类中指定方法时,如果有多个方法与调用兼容(例如,存在两 ... -
One Assertion Per Test(zz)
2007-05-18 10:15 2178zz from :http://www.artima.co ... -
One Expectation Per Test(zz)
2007-05-18 10:18 810zz From: http://jupitermoonbeam ... -
Presentation Model - Martin's "GUI Architectures" series (3)
2007-05-31 12:18 885zz from www.martinfowler.com To ... -
Passive View - Martin's "GUI Architectures" series (4)
2007-05-31 12:19 816zz from www.martinfowler.com To ... -
Rhino Mocks To The Rescure
2006-11-23 09:17 910http://developernotes.com/archi ... -
Some high level concepts
2006-11-23 09:25 883http://structuremap.sourceforge ... -
Singletons Are Evil
2006-11-23 09:56 699http://c2.com/cgi/wiki?Singleto ... -
Best and Worst Practices for Mock Objects
2006-11-23 10:00 601http://codebetter.com/blogs/jer ... -
小函数:让你的函数变短的九个好处
2006-12-04 22:15 807Small Methods: Nine Benefits ... -
UML序列图(zz)
2007-03-19 11:28 1629级别: 初级 Donald BellIBM 2005 年 2 ... -
重写方法不被认为是在类上声明的
2007-03-22 14:54 789当在类中指定方法时,如果有多个方法与调用兼容(例如,存在两 ... -
One Assertion Per Test(zz)
2007-05-18 10:15 793zz from :http://www.artima.co ... -
One Expectation Per Test(zz)
2007-05-18 10:18 1215zz From: http://jupitermoonbeam ...
相关推荐
2. **多线程**:为了同时处理多个机器人并实时更新GUI,多线程技术可能会被用来并发地处理不同的任务。 3. **GUI框架**:可能使用了Qt、wxWidgets或GTK+等C++ GUI库来构建用户界面,这些库提供了丰富的控件和事件...
2. **Supervising Controller**: 相比Passive View,Supervising Controller模式允许视图有一些简单的数据绑定和基本的事件处理。Presenter仍然负责处理复杂的业务逻辑和视图之间的协调工作,但它并不直接控制视图...
而Supervising Controller模式则允许View有一些简单的逻辑,但主要逻辑仍在Presenter。 总的来说,SaflyMVP可能是一个关于如何在项目中实施MVP架构的资源,帮助开发者理解并应用这一模式,从而提升应用的质量和可...
The main task of the website is to crawl the prices and sales volume of vegetables in Guizhou's vegetable markets, effectively supervising the vegetable price situation through web crawling data, and...
在实际开发中,MVP模式有多种变体,比如Passive View、Supervising Controller等,可以根据项目的复杂度和需求选择合适的实现方式。MVPFirstDo项目作为一个简单的示例,有助于初学者理解MVP模式的基本概念和工作流程...
实际开发中,可以根据项目需求灵活调整MVP的具体实现,比如使用 Passive View 或 Supervising Controller 变种。总之,MVP模式是Android开发中一种实用的设计模式,能够提升代码质量并简化项目管理。
A tool for supervising and retrying command line executions. Runs something until it succeeds. Options: -r, --retries number How many times to retry the command if it fails (-1 is infinite tries, ...
MVP模式通常分为 Passive View、Supervising Controller 和 Presentation Model 三种变体,这里可能探讨了哪一种或多种变体如何适应远程通信的需求,比如处理延迟、数据同步、错误处理等问题。 【压缩包子文件的...
2. Supervising Controller:视图保留一定的逻辑,但主要的业务逻辑仍在Presenter中。视图可能会直接更新自身,但大的更改仍由Presenter控制。 **C#中的MVP实践** 在C#开发中,MVP模式可以显著提升代码的组织结构...
2. **Supervising Controller**:View有一些简单的逻辑,但仍依赖Presenter来处理复杂的业务逻辑。 3. **Clean MVP**:这是一种更为严格的MVP变体,强调Presenter的独立性,避免了View和Presenter之间的直接引用,...
2. ** Supervising Controller MVP**:视图有一定的处理能力,例如可以处理简单的事件,而复杂的逻辑仍然在呈现器中处理。 3. ** Clean MVP**:这种变体强调了更严格的分离,通常会有单独的数据层接口,使得呈现器...
在C#开发中,MVP模式通常分为三种类型: Passive View、Supervising Controller 和 Presentation Model。其中,Passive View是最基础的形式,View完全被动,不包含任何业务逻辑,所有的处理都由Presenter完成;...
**MVP模式详解** MVP(Model-View-Presenter)是一种软件设计模式,常用于Android和Web应用...在实际项目中,可以根据项目的规模和复杂度调整MVP的具体实现,例如使用 Passive View 或 Supervising Controller 变体。
在给定的文件内容中,提出了一个新颖的超节点选取与组织机制,命名为SSMRF(Supervising Super-nodes Mechanism based on Rationality Factors)。SSMRF的主要创新点在于: 1. 综合评估节点的物理性能、自愿性以及...
- **例句**:*The architect knew that his clients were very particular about the new house he had designed for them, and he was careful supervising the building all along the way.*(建筑师知道他的客户...
Go包,littleboss可以让你把你的程序变成一个self-supervising的二进制文件。 它作为一个子进程自行启动,监视它的生命周期,如果它退出就重新加载它,并且可以指示它用一个新的二进制代替它。
approach to supervising neural networks by specifying constraints that should hold over the output space, rather than direct examples of input-output pairs. These constraints are derived from prior ...
age, we learn that the practice of building one's own home in the United States has become a popular alternative for those seeking affordable housing options, particularly among young couples who ...
This includes supervising teachers and students, conducting electrical inspections, assessing the adequacy of facilities, devising应急预案, and strengthening safety awareness training. 2.1 ...
而“supervising software”可能就是PLC监控系统的可执行文件,用户需要按照“安装说明.txt”的指示进行操作,以便在电脑上运行并使用这款软件。 总的来说,【PLC监控系统 升级版】是一个强大的、免费的PLC管理工具...