Chris Donnan : Programming – Brooklyn Style
software, trading, family, fun
Posted .net, c#, patterns and principals, programming on Tuesday, March 14th, 2006.
Sam Gentile has 2 recent posts that made me realize – I never blogged the most excellent Microsoft CAB (Composite UI Application Block) yet! First – let me say – that I am a huge fan of CAB. I have spent the better part of the past few years just building Smart Client applications. I have also spent lots of that time building a reusable Desktop Application Framework (DAF). This makes CAB right up my alley.
Many times looking at CAB I have had to say to myself “Well – they handled that aspect of the application this way – nice – we did 99% the same thing”. That is nice personal validation as well as nice validation for the teams that I have worked with. I have also said to myself – “Well – they certainly did that better than we did”. This is a great learning point. Sometimes – I have had to ask “well – should they (the CAB team) have done this more like we did – or like someone else did?”.
One of the things that I am wondering about presently is the Injection Model/ ObjectBuilder infrastructure.
IoC/ Dependency Injection/ The Hollywood Principal
See: @PicoContainer.org, @MartinFowler.com
For those not familiar with IoC (or another of it’s monikers) – the idea is pretty simple. You classes/ components should depend on abstractions (interfaces usually) and any dependencies should be able to be passed in via constructors (Constructor Injection) or setters (Setter Injection). Read the refs to see why if you do not follow – suffice it to say – it makes your code more flexible I and others have found.
Spring
In any case – I have been using SpringFramework.net for our desktop portion of our current application (Credit Derivative Trading Application for traders). The Java based middle tier members of my team is also using the original – SpringFramework for Java.
In spring – you configure dependencies in XML. So – lets say I was looking for the object with the ID “Views.MainBlotter”. This would give me some class (indicated by the “type” attribute). This would also set any constructor args (using “constructor-arg” tags) and/ or set any dependent properties (using “property” tags).

CAB’s ObjectBuilder
CAB takes a different approach. They use attributes on the classes to indicate dependencies. Then there are Builder classes (ObjectBuilders) that manage to specify the implementer at various stages of the application lifecycle (‘the pipeline’ of lifecycle events moreover)…

There are several ‘out of the box’ strategies for setting properties including:
Table 1 – The stages of starting up a Composite UI Application Block application
| Pipeline stage | ObjectBuilder Strategies |
|---|---|
| PreCreation | TypeMappingStrategy SingletonStrategy ConstructorReflectionStrategy |
| Creation | CreationStrategy |
| Initialization | PropertySetterStrategy PropertyReflectionStrategy MethodReflectionStrategy MethodExecutionStrategy |
| PostInitialization | BuilderAwareStrategy |
The application blocks that use ObjectBuilder add specific strategies to the pipeline, and you can add your own strategies if required.
These strategies are all useful at different stages of the ‘pipeline’ of the application lifecycle. There is certainly lots of flexibility here with this set of object creation notions. I am not sure that it is all necessary – or that I like it as compared to spring – BUT this may just be because I am accustomed to spring. That being said – I am going to try some work with the ObjectBuilder infrastructure in CAB and we will see where I stand after doing an apples to apples comparison.
More eventually;
Chris
Comment on this post below
You must be logged in to post a comment.
You can leave a response, or trackback from your own site.







