Most UI development is dependent on pages/ screens
communicating with each other. Historically there have been two
approaches to UI design. Model View Controller ( also known
sometimes as model 2) and the more simplistic model where every
UI page/ screen knows about every other screen.This is also known
as Model One architecture.
MVC UI architecture provides a clean separation of UI logic
from the business code by providing a layer of separation between
the two. This makes code maintainable and reusable.
Languages like Java have adopted this approach with frameworks
like Struts and Web Work. ASP.NET by default is based on a the
concept of a controller for every page in the form of a code
behind where all the event handling occurs. However every page in
this structure knows about every other page that it has to
communicate to.
This lends to lots of code in the code behind class that
does not easily lend to reuse. Another drawback is in testing the
code behind. Since the code behind requires a container to run
in, it becomes increasingly difficult to test the logic that goes
in these classes.
UI Process Application block from Microsoft is an API that is
written for large applications that have complex interactions.The
process block does not assume a web based system. It can be used
for rich clients and can be easily be extended for other custom
clients
This application block provides session management, task
management, state management and navigation management among
other features.
MSDN has a good article that introduces the basics of this
application block . Reading the intro on MSDN may be beneficial
before reading this article.
This article explains techniques for testing code using UIP
and other practical suggestions that will allow for understanding
the application clock better. This article is focused around
developing web based systems. However some of the concepts may
very well be applied to other kinds of systems.
The main parts of the UIP block are the View and the
Controller. Every page is a sub class of WebFormView. Views talk
to the backend using controller. Views know only about
themselves. Controllers in the application blocks are basically
commands. Every view interacts with a controller.
Views are routed based on a navigation graph. Think of this as the sequence of steps or pages the user is required to go through. Here is an example of an entry in the config file
A page called MyHome is part of a NavigationGraph called MyController which is defined in the config file as a WebFormViewManager.
<views>
<view name="MyHome" type="home.aspx" controller="MyController" />
</views>


A - UIProcess.StartNavigationPath("{The name of the path For B}")
B- user does something that needs to be stored for the
next screen C to use.
In B we call
MyController.SomeMethod( passTheData )
and in the controller we can store in the State as MyController.State(anObject, passTheData)
State is a sub class of DictionaryBase, an abstract class that
allows for strongly typed key and value pairs in its sub classes.
Using the state is how caching is done in a given navigation
path. This is different from the System.Web.Cache where is Key
cannot be any object than a string.Me.State.NavigateValue = "fail"When writing a unit test, the code above will fail as there will be no place to navigate to when a NUnit test is running.
Navigate()
Public Overridable Sub AddToCart(productId As Integer, quantity As
Integer)
Dim cart As New CartBusinessObject()= businessComponent.GetCart(user)
if cart.Validate()
Then
cart.AddToCart(Cart.CartItems, productId, quantity)
businessComponent.SaveCart(cart)
End If
Me.State.NavigateValue = "addItem"
Navigate()
End Sub 'AddToCart
Public Class AddProduct
Inherits ICommand
Public Sub New (user as User, productId As Integer, quantity As Integer)
'Initialize here - Not shown
End Sub 'New
Public Sub Execute()
Dim cart As New CartBusinessObject()= businessComponent.GetCart(user)
if cart.Validate()
Then
cart.AddToCart(Cart.CartItems, productId, quantity)
businessComponent.SaveCart(cart)
End If
End Sub
End Class 'AddProduct'
Public Overridable Sub AddToCart(productId As Integer, quantity AsThe only thing that cannot be tested is the navigation which is certain to be tested developing the UI.
Integer)
_command.Execute(productId,quantity,user)
Me.State.NavigateValue = "addItem"
Navigate()
End Sub 'AddToCart