Silverlight and WPF development have lead to the uptake of a number of development patterns many of which were first introduced by Martin Fowler or which are variations of them. This post contains notes about the various patterns that are appearing in frameworks like Caliburn.Micro or Prism.
These patterns are put together to form a presentation framework.
Firstly, there is the Application Controller:
“A centralized point for handling screen navigation and the flow of an application.” – http://martinfowler.com/eaaCatalog/applicationController.html (Martin Fowler)
The Application Controller is often comprised of a number of elements such as:
- Screen(s)
- Screen Factories
- Screen Factory Registry
- Screen Conductor
- Screen Collection
- Subject
Screen
- The class that handles coordinates the Model, View and ViewModel.
- Coordinates the marrying of a View to a ViewModel (the View doesn’t know about the ViewModel, the ViewModel doesn’t know about View).
- Implements the IScreen interface.
IScreen
- An interface that all Screens will implement.
- Requires methods such as CanLeave() and CleanUp().
Screen Factory
- There is a one-to-one relationship between Screen Factories and Screens.
- Screen Factories implement the IScreenFactory interface
- The Screen Factories are registered with the presentation framework (i.e. the Screen Factory Registry singleton class).
- Screen Factories are used by the Screen Conductor to instantiate screens.
IScreenFactory
- Requires a CreateScreen() method.
Screen Factory Registry
- The Screen Factory Registry contains a registry of all of the screen factories.
- Modules can register their Screen Factory classes with the Screen Factory Registry.
- The Screen Factory Registry has methods including GetFactory(), HasFactory(), and a Screen Factory Dictionary
Screen Conductor
- The Screen Conductor coordinates the creation and destruction of screens.
- The Screen Conductor makes use of the Screen Factory Registry which it uses to create Screens as necessary.
- Screen creation includes screen visibility, screen location, loading Subjects into screens, etc.
- The Screen Conductor has a Screen Collection; a collection of all activated screen instances.
- The Screen Conductor is often a singleton.
Screen Collection
- The Screen Conductor has a Screen Collection which contains all of the activated screen instances.
- The Screen Collection is maintained by the Screen Conductor.
Subject
- The Subject is analogous to the Model; it’s what is required by the screen to fulfil its purpose.
After the Application Controller there is the Application Shell.
Application Shell
- The Application Shell is analogous to the main form in the application.
- The responsibility of the shell is to hold the main components of the user interface (e.g. menus, ribbons, panels, docking managers, etc.) for the screens that get activated later.
There sometimes are other elements that are combined with the above as part of the Presentation Framework.
Bootstrapper
- The Bootstrapper is responsible for instantiating elements like the Application Shell and the IoC container (should one be used).
- The Bootstrapper can also be used to activate services used by the application (e.g. caching service).