Archive for May, 2006
In my previous post, I refactored CAB Smart Part Quick Start project to use Presentation Model. This time I refactored the project to use Model View Presenter. Note: the Presenter class is borrowed from Smart Client Software Factory, SC-SF.
Download: Source for PM, Source for MVP
They can be added to Smart Part QuickStart Solution for comparison.
The difference is that in MVP the presenter uses the interfaces to push data into the views. That presenter refers to views. In PM, views pull data from the presentation model. Views refer to pm via interface. The pm implements the interfaces. Personally,
I prefer PM to MVP. I successfully used the PM pattern in several projects.
My thougths are,
What esstentially MVP and PM do is to take the state and behavior of the presentation out of view. The views are dumb. They do nothing other than data binding and bypass user inputs.
But in MVP, although it splits one “autonomous View” into two parts, actually presenter and view are logically one thing, physically two class. When adding a new view, a new presenter is required.
In PM, it is a decoupled structure. Presentation model has no idea about view(s). It just holds the state and raise events. Adding new views needs no changes to the PM. View can also choose to connect different presentation model.
The Smart Client Software Factory recommand MVP over PM, “The rationale behind MVP as implemented in SC-SF is to encourage unit testing …” Read this thread.
So, I created two projects for the two patterns. Next I will try to unit tests for them to see.
May 19th, 2006
Composite UI Application Block (CAB) is really a powerful framework for smart client applications. It comes with samples implementing the Model View Control (MVC) pattern and the Model View Presenter (MVP) pattern. There is actually a third pattern called Presentation Model. See the pictures from http://jgoodies.com/articles/patterns-and-binding.pdf.
As described in Martin Fowler’s article (MVP, PM), the presenter in MVP has no state and the views need to provide interface allow presenter to manipulate them. The Presentation Model holds and synchronizes the state, but no need to create view interfaces.
Choice between MVP and PM, as per Martin Fowler’s article:
This decision would be strongly influenced by a decent framework that supports such synchronization. If you have such a thing then Presentation Model seems the better choice.
Compare to MVC or MVP, I prefer using the Presentation Model, because it has a centralized place to store state/data and centralized event source to notify views to update themselves. The CAB’s Event Broker is perfect for notification. So I modified the Smart Part Quick Start Project to become the ”Presentation Model” pattern. Here is the Source code.
What have I done?
- Refactor to extract interface ICustomerListView and ICustomerDetailView from the views*.
- Added CustomerPresentationModel class that implements the above two interfaces.
- Define the CustomerPresentationModel class as Service. **
- Inject the CustomerPresentationModel instances into views using service dependency injection. ***
- Published events CustomerSelected events CustomerCommentsSelected from the CustomerPresentationModel class.
- Subscribed the above events in BrowseCustomerWorkItem and ViewCustomerWorkItem
* Extract interface from the views sound very much similar to MVP, isn’t it? The difference is that in MVP, the presenter uses the interfaces to push data into the views, means that presenter refers to views. In PM, the controller implements the interface. The views pull data from the controller, means that views refer to controller. The “refer to” is a very good case of using depedency injection.
**
[Service]
public class CustomerPresentationModel: ICustomerDetailView, ICustomerListView
{
}
***
public partial class CustomerListView : TitledSmartPart
{
private ICustomerListView controller = null;
[ServiceDependency(Required = true, Type = typeof(CustomerPresentationModel))]
public ICustomerListView Controller
{
set { controller = value; }
}
….
}
Tags: smart client Composite UI Application Block MVC Model View Presenter Presentation Model injection
May 15th, 2006
ç»§ç» VSLive Toronto çš„åŽç»æ•…事。 上次记录了 SQL/e,这次是关于 Daniel Cazzulino çš„å‘言 《Microsoft p&p ObjectBuilder》。å¬å®Œè¿™ä¸ªæ¼”讲å‘现最近周围的事情还都å‘生了些关è”。
首先是日å‰ä¹°äº†æœ¬ä¹¦ 《Head Up Design Patternsã€‹ã€‚å®ƒçš„ç¬¬ä¸€ç« å°±ä»¥ä¸€ä¸ªå¼•äººå…¥èƒœçš„æ•…äº‹ä»‹ç»äº†è®¾è®¡æ¨¡å¼çš„ Strategy Pattern。这个模å¼çš„好处多多,但是负作用是会产生了很多相互关è”的类。如何按照åˆç†åœ°åˆ›å»ºè¿™äº›ç±»ï¼Œå¹¶æŠŠå®ƒä»¬ç»„和起æ¥ã€‚这就引出了å¦å¤–一个è¯é¢˜ Inversion of Control / Dependency Injection。
è¿™å‡ å¤©å¸®å¥³å„¿å¤ä¹ 准备ä¹ç†è€ƒè¯•,还碰到了 Interval Inversion / Triad Inversion,æžå¾—我就很头æ˜ã€‚Dependency Injection 好åƒè¿˜å¥½ç†è§£äº›ã€‚
Daniel Cazzulino 讲的 ObjectBuilder 就是一个具有 dependency injection 功能的轻é‡çº§å¯¹è±¡å®¹å™¨*。 ObjectBuilder 是 ï¼ï¼³ patterns & practices Composite UI Application Block ä»¥åŠ Enterprise Library çš„æ ¸å¿ƒéƒ¨åˆ†ã€‚
这就åˆå¼•到了 CAB - Composite UI Application Block。也是ä¸ä¹…å‰ WB Editor 3.0 的设计已ç»å¼€å§‹äº†ã€‚鉴于 2.0 ç‰ˆæœ¬ä¸ RAD æµæ¯’太深**,决定应该采用个好的系统结构,æ£åœ¨çŠ¹è±«ï¼Œæ˜¯å¦ç”¨è¿™ç¯‡ Implement a Microsoft Word-like Object Model for Your .NET Framework Application æ–‡ç« ä»‹ç»çš„æ–¹æ³•呢,还是用 CAB。
ç»è¿‡è†å¬ Daniel Cazzulino 的讲解,ä¸ä½†äº†è§£äº† OB çš„åŠŸèƒ½ï¼Œè¿˜äº†è§£äº†å…¶å†…éƒ¨çš„ä¸€äº›æœºåˆ¶ã€‚å› æ¤å†³å®šè¿›ä¸€æ¥å¦ä¹ 了一下 CAB Hands on Lab。于是得到结论就是 WB Editor 3.0 将采用 CAB。
Daniel Cazzulino 还讲了个有用的内容,Guidance Automation Toolkit / GAT,值得å†ç”¨ä¸€ç¯‡ç¬”记介ç»ã€‚
* è½»é‡çº§å¯¹è±¡å®¹å™¨å’Œ ** RAD æµæ¯’也å¯ä»¥è®²äº›æ•…事。
Tags: VSLive ObjectBuilder Strategy Pattern Inversion of Control Dependency Injection Composite UI Application Block CAB RAD
May 14th, 2006
During the WB Editor 2.5 testing, we found an interesting concurrency control issue. In this version, we allowed multiple program instance for ease of cross posting.
Now in multiple instance windows, user can setup blog server accounts differently. Which one is the winner?
“Last one wins” was disapproved by QA.
Maybe we need optimistic concurrency. I this case user will receive a dialog saying “another instance has modified the settings”, do you want to overwrite or discard or reload?
Another option is concurrency control with change notifications. Using FileSystemWatcher to detect changes of configuration file, but what should happen next in UI?
Tgas: WB Editor concurrency control Last one wins optimistic change notifications multiple instance blog cross posting FileSystemWatcher
May 10th, 2006
在 VSLive Toronto 上è§åˆ°ä¸¤ä¸ªäººç‰©ï¼ŒSteve Lasker å’Œ Daniel Cazzulino
Steve Lasker 介ç»äº†ä½¿ç”¨ SQL Server Everywhere çš„ Occasionally Connected Systems。 SQL Server Everywhere(SQL/e) 何须人也?原æ¥2-4å¹´å‰åš Pocket PC 程åºå°±ç›¸è¯†ï¼Œé‚£æ—¶å®ƒå« SQL Server CEï¼ŒåŽæ¥åˆå« SQL Server Mobile。 Visual Studio 2005 带的 SQL Server Mobile 被é™åˆ¶åªèƒ½è¿è¡Œåœ¨ Tablet PC 上。SQL/e 就是解除了这个é™åˆ¶çš„版本。SQL/e å› æ¤èƒ½è¿è¡Œåœ¨å°å¼ Windows 上。
SQL/e 计划在 2006年下åŠå¹´å‘布。 Steve 演示了目å‰å¦‚何在 VS 2005 ä¸è¯•验开å‘的和å¯ä»¥é€šè¿‡ ClickOnce 安装的办法。
这就解决了一个版本 WB Editor 的数æ®åº“选择问题。 æœ¬æ¥æ£åœ¨çŠ¹è±«æ˜¯å¦åº”该用 SQL Server 2005 Express (SQL/x)。这个家伙 55Mï¼Œè¿˜éœ€è¦ Admin 用户æƒé™æ‰èƒ½å®‰è£…。 比较 SQL/x å’Œ SQL/e,SQL/e æ‰ 1.4M。看æ¥SQL/e æ›´åŠ é€‚åˆ WB Editor 3.0。
Daniel Cazzulino 讲的内容也很有用,将会在下一篇笔记内介ç»ã€‚
May 8th, 2006