Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Design using MVP pattern

Design using MVP pattern

Scheduled Pinned Locked Moved ASP.NET
designregexarchitecturequestionannouncement
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cybernate
    wrote on last edited by
    #1

    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?

    Regards, Cybernate

    J N 2 Replies Last reply
    0
    • C Cybernate

      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?

      Regards, Cybernate

      J Offline
      J Offline
      Jeremy Likness
      wrote on last edited by
      #2

      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.

      Jeremy Likness Latest Article: Hierarchal Data Templates in Silverlight Blog: C#er : IMage

      C 1 Reply Last reply
      0
      • J Jeremy Likness

        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.

        Jeremy Likness Latest Article: Hierarchal Data Templates in Silverlight Blog: C#er : IMage

        C Offline
        C Offline
        Cybernate
        wrote on last edited by
        #3

        Thanks Jeremy. I tried to provide my question with an example. I have a scenario where I have to display a view with around 30 fields(some are textboxes and some are Dropdowns) and the Business Object to represent the entity would be something like: [CODE] Parent { PField1 PField2 . . . . PField19 PField20 List<Son> Sons; List<Daughters> Daughters; } Son { SField1 SField2 SField3 } Daughter { DField1 DField2 DField3 DField4 DField5 } [/CODE] Am capturing/displaying the whole business entity in a single view. Now the user can change the base fields of a parent or change the fields of a son/daughter. Now how should I handle the change events for each field in the view, should I delegate the change events to the Presenter and then let presenter update the view. This requires to define 22 events in the View and then 22 delegate events in view and 22 event handlers in the presentation layer. Somehow am not having a good feeling about this design. Can you please advise?

        Regards, Cybernate

        modified on Tuesday, July 28, 2009 4:01 PM

        1 Reply Last reply
        0
        • C Cybernate

          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?

          Regards, Cybernate

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          AFAIK, MVP is not well suited for web-applications. It works well with stand-alone applications. You may try the MVC model. ASP.NET has a MVC framework available. Give it a try.

          Cybernate wrote:

          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.

          That is ugly. You can have only one method in the presentation layer which takes an aggregate data structure and does the UI binding. Read this[^] MSDN article which takes MVP pattern in detail. :)

          Navaneeth How to use google | Ask smart questions

          C 1 Reply Last reply
          0
          • N N a v a n e e t h

            AFAIK, MVP is not well suited for web-applications. It works well with stand-alone applications. You may try the MVC model. ASP.NET has a MVC framework available. Give it a try.

            Cybernate wrote:

            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.

            That is ugly. You can have only one method in the presentation layer which takes an aggregate data structure and does the UI binding. Read this[^] MSDN article which takes MVP pattern in detail. :)

            Navaneeth How to use google | Ask smart questions

            C Offline
            C Offline
            Cybernate
            wrote on last edited by
            #5

            Thanks for your inputs. I am not sure if I agree with you on MVP not suited for Web Apps. Regarding the 30 Events statement I was being sarcastic. Thanks for trying though.

            Regards, Cybernate

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups