Andre de Cavaignac

Let's blog it out...

Production CAB: CAB Stock Trading Demo Application

Download sample VS.NET 2005 Solution File

Download Presentation as PowerPoint 2007 (pptx)

Download Presentation as PDF

 

The Microsoft UI Composite Application Block (CAB) is an extremely powerful Microsoft “Best Practices” pattern for building complex UI applications with reusable and pluggable components.  It is a framework of suggested guidelines that allow for extensibility and flexibility in UI application design.  I will not go into detail about CAB in this article, as it is covered in many other places, however I will be brief on CAB’s benefits below.

CAB’s benefits stem from

  • Composition patterns using dependency injection to create objects with “loose” references
  • Declarative event brokering for multi subscriber/publisher events without subscriber needing to know of publisher
  • Saving of application state
  • Multiple independent assemblies loaded in one shell, allowing for multiple developers to easily split up an application when developing.

To find more information related specifically to CAB, see Microsoft’s Patterns & Practices site.

 

Production CAB

A few weeks ago, David Barnhill and I gave a presentation at Lab49 about the use of CAB.  We got a bunch of positive feedback regarding our demo, and some good questions came out of it into which we researched further.  Both of us (on separate projects), are currently utilizing CAB in our production applications at a financial firm.  There have been many benefits to this, including reuse and simplified multi-developer working environment.

Learning CAB was an interesting experience.  The concept is certainly different than most others, especially because of the extensive use of dependency injection,  and attributes.  CAB forces you to think on a “Work Item” basis, where you break up your tasks and UI’s into small bits and loosely couple them together.   What we both found was that after building a small app (such as the demo included in this blog post), CAB  quickly becomes intuitive and very friendly to use.

Demo

If you haven’t already, I suggest you look over the PowerPoint slideshow provided here.  The slides were originally created in PowerPoint 2007, so if you don’t have it, you may download the PDF.  These slides describe our experience with CAB and give a brief overview of CAB concepts.  Hats off to Matt Davey who influenced some of the slide design from his CAB presentation in the UK.

Download Presentation as PowerPoint 2007 (pptx)

Download Presentation as PDF

 

To properly show the use of CAB in a financial application, we decided to create a simple (and admittedly ugly) stock trading application.  The application has the following features:

  • A virtual “real-time” market to update stock quotes
  • A grid of all market stocks and their current values
  • A feature to buy and sell market stocks
  • A trace window to see what the application is doing.

We took an approach to ensure that we used CAB to its highest level.

First, we designed a shared assembly with an IMarket  that contained Buy and Sell methods.  This was an interface that ensured and UI components would not be coupled to the market service.  The concrete class of Market was then created in the shell, but not distributed to the other modules.  Market was designed to implement IMarket, and also update stock ticker symbols.  Market exposed three events:  TickerUpdated, BuyOrderCreated, SellOrderCreated.  These events were not exposed through IMarket¸ but rather are accessed through the event broker by using the [EventSubscription] attribute on subscribers.

 

 

Next, we created a separate module to hold our UI components.  This module referenced the shared libraries (with the IMarket interface) but not the shell.  The module creates the majority of the components, including the race window, ticker list and buy/sell window.  We use [ServiceDependency] to get the IMarket in any scenarios where we need access to buy/sell features.  For ticker updates and other market events, [EventSubscription] attribute is used.

The workflow of this system is as follows:

  • Form opens
    • TickerListWorkItem creates TickerModel to listen to Market.TickerUpdated
    • TraceWorkItem listens to all the events on the Market to trace verbose messages.
  • User clicks on a row in the list
    • Invokes BuySellInvoked event through the event broker
    • The BuySellWorkItem picks this up and creates a new smart part to handle the order.
    • Gets the IMarket from dependency injection to place the buy/sell.
    • User Clicks buy
      • Market function is triggered
      • Trace gets event that a buy/sell occurred and writes to the trace window

 

(Click Image To Enlarge)

 

The entire development of this application took only an hour and a half.  It is fairly impressive what you can get running in CAB in such a limited amount of time.  We suggest you take a look!

 

Download sample VS.NET 2005 Solution File

Download Presentation as PowerPoint 2007 (pptx)

Download Presentation as PDF

Comments

Matt said:

Yeh, CAB works.  Anyone building a WinForm UI should take a look at CAB - or Spring DAF is it every gets completed.  IoC on the client is sensible and very useful.  I've been instrumental in bringing CAB into a number of investment banks, and in certain circles I'm even sadly becoming known as the CAB Evangelist - maybe I should get commission from Microsoft ;)
# October 8, 2006 10:06 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)