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:
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:
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?