There are many elements that make up CAB. When starting out, I found that a lot of the explanations I found just confused me. I will list some of them here and try to explain the way I understand them.
WorkItem
This is the most important element in CAB. It is basically a container that manages all the objects required to accomplish a certain task.
For example, I have a WorkItem for managing Products. It manages all of the commands/views and presenters required to list, view and edit Products.
The Views might be ProductsListView and ProductsDetailsView. WorkItem also contains state objects to manage the state of the workitem (eg: What product has been selected?).
The workitem contains all of the objects necessary to complete the task - this means the presenters/views never have to look outside of the WorkItem.
Every module created will contain a WorkItem. The WorkItem is controlled by a class called the WorkItemController which is used to initialize and run the module/workitem.
There is a RootWorkItem which is the toplevel WorkItem. All other WorkItems are connected through the root WorkItem.
SmartPart
SmartParts are the visual components of a module (basically a view). They are usually a UserControl that is shown somewhere on the main form.
WorkItems can contain one or more SmartParts to display. It is up to the WorkItem to decide when/where to display the SmartPart.
Workspaces
Workspaces are UI controls that can display SmartParts. A workspace decides how to display the SmartPart (eg: DockedPanel, Frame,Tab etc). WorkItems have a Workspace collection that contains all of the Workspaces it has available to use. WorkItems then display a SmartPart by adding it to a Workspace.
Workspaces need to be added to a WorkItem. These Workspaces are then visible to this WorkItem, as well as all of it's children WorkItems.
You can create a Workspace from any type of control by implementing the IWorkspace interface.
Services
The WorkItem class includes a Services collection that you can use to register/access services. A service is registered as an interface type - This allows you to change the implementation of the service without affecting anything else. For example, you could register a database access service, and then switch to another type of database at a later date.
You can use services for things such as logging, database access etc.
Event Broker
The event broker allows you to create events and have classes publish/subscribe to these events without knowing about one another. An event have one or more publishers, as well as one or more subscribers. It's a way to pass events and data around the application without having to set dependencies.
I think these are the parts of CAB that I use the most. In my next post, I will explain how these fit together and post some guidelines to follow when developing a CAB application. These guidelines will make debugging/future modifications easier and should keep your entire project well structured and clean.
Thursday, 10 May 2007
Subscribe to:
Posts (Atom)