MVP & CAB

Topics: CAB & Smart Client Software Factory
May 23, 2007 at 4:42 PM
Hi my question is about mvp in cab application
as i understand the presenter communicates with the view through an appropriate interface
and the view holds an instance of the presenter
so far so good

1)My problem concerns the role of the controller(workItemController) and its interaction with the view
does the controller get the data via ServiceAgent or mybe this job is intended for the presenter (also via service agent)?

2) If the controller gets the data from the serviceAgent what is the right way to pass the data to the View ?
the controller holds and instance of IView so i can Invoke the method that i wont directly from the controller
IView.SetData(data) or mybe store the data in the workitem.Items collection and then the presenter will get the data from the items and assign it to the view.

Please advise me about the best/right way to do this

Thanks Alex






May 23, 2007 at 7:31 PM
Edited May 23, 2007 at 7:44 PM
My experience with the MVP pattern is that the presenter will get and retrieve data from the view and it will contain the logic and call services. This pattern allowed me to take out logic from the view and have a more testable code (more coverage).
On the other hand I’ve used the WorkItemController as the orchestrator of one or more use cases. It will subscribe to events and handle commands, show views, add services to the workitem, etc.

The learning material I found most enlightening was:
- http://www.microsoft.com/downloads/details.aspx?familyid=5f9a8435-1651-4be2-956d-0446a89a7358&displaylang=en
- Bank Branch reference implementation
- SCSF's Hands on Labs (http://www.codeplex.com/smartclient/Wiki/View.aspx?title=Smart%20Client%20Software%20Factory&referringTitle=Home)

Hope it helps!

Luciano Panaro
http://staff.southworks.net/blogs/lpanaro
May 24, 2007 at 2:51 PM
Hi Luciano

Thanks for your help but i would really like to pin point my problem so i will do things the "Right way"
MyController
{
EventSubscription("ShowMyData" )
public ShowMyDataHandler(Status s)
{
//This event is fired from a smartpart passing a parameter which tells me how
// to filter the needed data. and my dilema is as follows

IView MyView; // The view instance is taken from the workitem.Smartparts collection
MyServiceAgent.GetData(s);
MyView.SetData(s);

// Or the alternative is and as i understand from you the right way to do this is
IView MyView;
WorkItem.Items.Add("MyData", MyServiceAgent.GetData(s));
// The next step would be to retrive the data from the items collection when the presenter OnViewReady is fired
// or mybe to store the Status parameter is the items collection and then Call the serviceAgent from the
// presenter.
}

}

Thanks for your help.
May 24, 2007 at 6:09 PM
Edited May 24, 2007 at 6:10 PM
Hi Alex,

I would put the logic inside the presenter and not in the controller.
You can inject the service to your presenter in order to work with it, resulting in something like this:
[ServiceDependency]
public IMyServiceAgent MyServiceAgent
{
    set { _myservice  = value; }
}  
 
public override void OnViewReady()
{
    MyDataType data = MyServiceAgent.GetData();
                      
    View.ShowData(data);
}  
May 31, 2007 at 8:44 PM
agree.
Jun 19, 2007 at 3:29 AM
Hi,
I had a go at learning CAB last year, with the bankteller example - but put it on the shelf as having a huge learning curve.
Now I am ready to come back to CAB & SCSF.
I was listening to Ron Jacob's program about the "Presenter First" pattern at http://channel9.msdn.com/ShowPost.aspx?PostID=312305 which sounds very cool.
This program explains how the use cases should go in the presenter class; with the presenter class accessing a model class and a view class via interfaces

For example use case "When the user clicks load, the data loads into the grid " would get expressed by presenter calling both the model and the view via interfaces,

However from my earlier learning - I thought the use cases were meant to go in the work item.. Has there been a change in guidance regarding this?

Thanks
Kirsten