1

I'm refactoring a big-scale ASP.NET application written with WebForms which has a very unflexible design of view+code-behind. For this refactor, I'm using MVP Architecture (Model-View-Presenter), which uses a Page Controller approach for pages and controls.

Writing a controllers for pages, I've faced a problem of reusability. The following diagram expresses a small sample which will illustrate my problem:

http://i61.tinypic.com/atoltt.jpg

RegistrationView is a view with a form that allows a user to register (introducing data like Name, Address, Country... and then modifies this data through the controller). EditAddressView retrieves already-existing data about the user, allows for modification and then modifies the data back to the model.

As you may see, there are some parts in common in the controllers (more specifically, the storage of data). I'd wish to reuse the part of the code where data is stored, so I considered a three options to deal with this:

  • Create a superclass that includes the code to be reused, and then make controllers inherit this class and use the store algorithm.
  • Create a kind of "library" layer (i.e. UserManagerLibrary) which both controllers would make use of and make respective calls to it.
  • Implement a somewhat component system and create controllers that would manage these "components". This diagram illustrates my approach:

enter image description here

NOTE: CountryRetriever obtains a list of countries to populate a dropdown menu.

In this approach, I make views to conform to several interfaces, which, together, define a view. Then I bind each view with several page-controllers depending on the interfaces the views implement. This way, I think I could easily create new views and expand functionalities of existing ones (for instance, I could expand the EditAddressView with deletion functionality by making it implement a IUserDelete interface).

I think that this approach would allow me to maximize my code reusability and Single Responsibility Principle in a MVP architecture, yet I have the feeling I'm somehow violating the Page-Controller pattern, and the feeling that this approach may have a big drawback in the future for me (I don't know, that's why I'm asking if my solution is good).

Can anyone enlighten me on this matter?

Thank you

  • What caused you to roll your own MVP solution, rather than adopting ASP.NET MVC? – Robert Harvey Apr 1 '14 at 21:20
  • The reason is that I inherited a rather huge project which was entirely made in Webforms, and a complete reprogramming to MVC is unfeasible at the time being. BTW, just curious, how would MVC solve my problem? – David Jiménez Martínez Apr 1 '14 at 21:25
  • MVC already has a bunch of this functionality completed, although to be fair, it doesn't include the Observer pattern unless you add some frontend Javascript frameworks to it. – Robert Harvey Apr 1 '14 at 21:29
  • I guess so, but... in which way? I have some notions about MVC (I'm more experienced in Webforms, though) and I would wish to grasp the idea about how would MVC solve my problem for future projects. – David Jiménez Martínez Apr 1 '14 at 21:31
  • In broad brush strokes, I'd say that you're trying to use MVP now because you need a bridge from Webforms to something better, whereas ASP.NET MVC would probably be better for a greenfield project. – Robert Harvey Apr 1 '14 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.