Mobile CAB Question inter View communication

Topics: Mobile Client Software Factory
Sep 29, 2006 at 1:46 AM
originally posted by: johnkattenhorn

Hi,

I've got several views which are all displayed using a Tabbed workspace. They need to access the same Business Entitiy object, e.g. Each User Control in each view on each tab needs to update different properties on the business entity.

What's the best way to pass around the business entity so that each of the Views can access it ?

In addtion i would like an event on one View i.e. CheckBox ticked to be processed and change things on the other tabs, is this possible ?

Thanks

John
Oct 3, 2006 at 2:37 AM
originally posted by: HargroveMJ

Hi John

I have a similar scenario and my solution which I think I've copied from one of the examples/RI is to have a single presenter managing the whole tabbed workspace then its simply a matter of wiring up the events from the individual views to the presenter which updates a common business entity. I'm not sure if this is the way to go but its working for me at the moment.

An alternative solution I was thinking around was a common named business entity held in a workitem, when required each view updates the Business entity and fires an event (using the event broker) e.g. "Business Entity Changed" which they each in turn subscribe to so when they see the event fire they refresh their own version of the BE. A variation on this would be that the event fired to say that the BE had been updated actually carried the BE in the EventArgs - The event broker architecture will only handle System.EventArgs but you can up/down cast to/from DataEventArgs. What I'm not sure about with this solution because I'm not that far round the learning curve,
1 Can an entity publish and subscirbe to the same event? If so you need to know when it was the same entity that fired the event as is responding to it otherwise you are doing unnecessary work. No biggy but I would think you need to account for that situation.
2 The other big unknown (for me) and bigger question is; can more than one entity publish the same event? If not then Its a road to nowhere because you need multiple publishers for the same event

Alternatively I think the "State" architecture provides the whole solution - a common place to store business entities and a "State Changed" event mechanism - thing is I haven't investigated it yet so not sure of the pro's and cons of using it. My concern would be that "State" in my view, is somewhere special - its sort of global - trickles down to descendants? and gets persisted? (if I ask) and so I'm not sure I want to be using it as a common scratchpad for business entities just so that they can be shared between view - seems like I could end up with all kinds of garbage in there.

The CheckBox tick can be solved in the same way either a single presenter or simply with the EventBroker publish and subscribe - my guess anyway.

Sorry for the confused thinking - but I haven't seen a definitive solution on how to implement sharing so my thoughts aren't clear.

Hope this helps
Regards
Mark
Oct 3, 2006 at 10:15 AM
originally posted by: johnkattenhorn

Hi,

Thanks for your feedback, i figured on the state mechnism as well. I'll do some work with it and let you know how i get on with it.

Thanks

John