Click here to Skip to main content
12,403,699 members (72,028 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: (untagged)
Hi,
I am trying to implement a site(Read/Update/Delete operations site) using MVP pattern. Also trying to keep the presentation layer UI agnostic(i.e. Presentation layer should work with a Web Client/Windows Client).
Now I have a domain object with around 30 fields/attributes and all of these fields are editable in the UI(View).

I want to propogate the change in any field to the Presentation layer. The only solution I can think of is to define 30 events!!! in the View and 30 handlers in the Presentation layer or define 30 setter methods in the presentation layer for the 30 event handlers in the view.

Am not comfortable with this design.
Can any one provide me a solution or a direction on this?

Posted 28-Jul-09 5:15am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

First, why should the presentation layer work in two different presentation models?

You mean the controller?

I can see this:

Model
Controller
View - one instance for web, one instance for web form

That makes more sense to me.

I'm also assuming your changes are to "something" not just random fields, but fields that belong to an object.

So why not maintain the original object state in the controller:

Controller<T> where T: class

T _state;

Have a typed args, something like:

public class TypedArgs<T> : EventArgs where T: class
{
public T Value { get; set; }
}

Create an interface for your views:

public interface IView<T> where T: class
{
event EventHandler<TypedArgs<T>> Changed;
}

then you can raise Changed with the new entity in the view, and have the controller register. Just pass in IView to the controller so it doesn't care if it's a user control or a web form, and when Changed is raised, it can compare e.Value to the stored state and decide what to do.

  Permalink  
  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 28 Jul 2009
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100