CAB Best Practices

This past week I attended the Smart Client Baseline Architecture Toolkit (SC-BAT) workshop out in Redmond.  Overall it was a very beneficial week.  I learned a lot about CAB best practices and also got to meet some members of the core patterns and practices team as well as some other Microsoft employees whom I had “heard” of.

It was also my first trip out to Redmond so it was fun to see what Microsoft was like…it’s HUGE.  Anyway I thought I’d get going with some posts on what I learned and how I’ll apply what I learned.  This first post is a simple list of the best practices that I came away with.  Hopefully future posts will be more beneficial for those who don’t know much about CAB.

  • There should be a 1–1 relationship between a view and it’s presenter.  Presenters are seen as an implementation detail of a view so nothing outside of the view should know about the presenters existence.  [CreateNew] is your friend when it comes to creating a presenter for your view.
  • Since views know about their presenter (and vice versa) any work that needs to be done by the view should be directly delegated to it’s presenter.  The presenter should handle all work that the view needs done.  The view should just display data and be extremely “light”.  The event broker should NOT be use to communicate between a view and it’s presenter.

private void button_Click(object sender, EventArgs e) {
   _presenter.DoMyButtonClickStuff();
}

  • If views need to “communicate” between each other they should use EventPublication/EventSubscription.
  • WorkItem’s sole purpose in life is to be a container.  Rather then being anything “Use Case” related treat WorkItem as what it is, a container.
  • The logic necessary for adding views, services, and etc. to a  WorkItem should live inside a Controller class.  Since the controller needs to know about it’s WorkItem the ControlledWorkItem class should become one of your good friends.
  • Controllers are used to get things wired up and running, and for adding everything necessary to the container (aka WorkItem).
  • If possible your views should implement the ISmartPartProvider interface.  This allows the view to determine how it is displayed within your workspace(s).
  • Views and Presenters should implement IDisposable so they can be cleaned up properly.
  • The Guidance Automation Toolkit is your friend.  Learn it, live it, love it!

# re: CAB Best Practices

Wednesday, March 22, 2006 11:27 PM by Jean-Philippe    
Hi Steve. We are currently learning about the CAB to use it in our application so we enjoy reading every bit of information we can get out hands on. We really liked your best practices and we strongly agree with you that it's not easy to learn at first. The only thing we find confusing about your best practices right now though is that you seem to be mixing the MVP can MVC patterns. The first two points talk about MVP, then there are a few generic points, then a few about the MVC, and then back to the MVP. Are we understanding this correctly?

# re: CAB Best Practices

Wednesday, March 22, 2006 11:28 PM by Jean-Philippe    
Hi Steve. We are currently learning about the CAB to use it in our application so we enjoy reading every bit of information we can get out hands on. We really liked your best practices and we strongly agree with you that it's not easy to learn at first. The only thing we find confusing about your best practices right now though is that you seem to be mixing the MVP can MVC patterns. The first two points talk about MVP, then there are a few generic points, then a few about the MVC, and then back to the MVP. Are we understanding this correctly?

# re: CAB Best Practices

Thursday, March 23, 2006 8:57 AM by chris donnan    
Thanks for the best practices list. My group is currently working on a .net 1x app. Since in the past I have developed Smartclient frameworks that were similar to CAB - I have been trying to keep the concepts and patterns as similar to the current CAB as possible. When the bank moves to 2.0 we will surely use CAB and the concepts will just work.

That being said - your post had a direct impact on our codebase. In the past we have used an MVC like pattern with 1 Controllers and N Views per logical domain. In this setup we used an event broker to send messages from the views to the controller.

In the current project we moved to using a 1-1 mapping of view to controller. We were still however using the event broker and calling it 'controller'. It smelled funny to me. Upon reading the post here - "The event broker should NOT be use to communicate between a view and it’s presenter" - it became clear - just make it proper view/ presenter.

So I renamed all the controllers presenters, replaced the event broker pubs/ subs and mimicked the pattern you have above - thus removing a layer of indirection.

The group thought it was all simpler. The bad smell went away.

Thanks for being a link in a piece of insight that made the codebase better.

-Chris

# re: CAB Best Practices

Thursday, March 23, 2006 1:10 PM by Steve    
Chris, I'm glad you found the post useful. There is a lot of stuff that can get pretty confusing with CAB so I've found that identifying and establishing the best practices helps make things more concrete.

# re: CAB Best Practices

Thursday, March 23, 2006 1:19 PM by Jean-Philippe    
Hi Steve. We are currently learning about the CAB to use it in our application so we enjoy reading every bit of information we can get out hands on. We really liked your best practices and we strongly agree with you that it's not easy to learn at first. The only thing we find confusing about your best practices right now though is that you seem to be mixing the MVP can MVC patterns. The first two points talk about MVP, then there are a few generic points, then a few about the MVC, and then back to the MVP. Are we understanding this correctly?

# unit testing?

Thursday, March 23, 2006 6:24 PM by Ben    
Steve, I've heard a lot about CAB recently and I want to use it on a project in the future. One thing that I havent heard much of, is the benefits of using CAB in regards to unit testing your win forms applications. I have studied the MVP pattern, and the testability of that pattern is apparent. I just cant seem to find any info on testing a CAB application. Did they touch on this at all at the workshop? thanks

# re: CAB Best Practices

Wednesday, April 05, 2006 2:49 PM by Jimmy    
Steve, was there any dicussion about Click Once deployment. I can't find anything useful for deployment when using third-party controls.

# re: CAB Best Practices

Thursday, August 17, 2006 7:32 AM by Nilesh    
Steve,

I found this post very helpful. It provided a good deal of information to me in initial stage of cab development.

Thanks again for sharing the right knowledge.

Post a Comment

 
 
Prove you're not a spammer: 
5 + 5 =