views:

32

answers:

1

I'm working on a web application. One of my co-workers has written some asp.net forms pages. The page classes all inherit from BasePageClass, which of course inherits from the Page class. I wish to add some MVC controllers that I've been told need to use the same logic implemented in the BasePageClass. Ordinarily, I would want to inherit the functions in the BasePageClass in the controller classes, but this breaks the inheritance heirarchy.

What is the best practice for solving this problem?

+2  A: 

If there is common functionality, I would suspect that this functionality should be separated out from the page/controller anyway. This is better OOP/D. Then both your controller base page and your System.Web.UI.Page base can both have properties returning classes that contain this common functionality.

(I've seen a lot of cases where stuff is crammed into the base page that should be elsewhere. Your need for this functionality to be in both the Pages and Controllers is likely just bringing this poor design to light, rather than being a problem in itself.)

Less likely to be what you want, but still a possibility:

  • You could also put your common functionality in a series of overloaded extension methods, where the first parameter is (a) System.Web.UI.Page and on the other overload (b) System.Web.Mvc.Controller.
  • Both your base page and base controller could implement a common interface, wrapping functionality stored in a common place.
  • Pull this functionality out altogether and do it as needed in your controler-logic and code-behinds.
Patrick Karcher
Patrick, I wonder where you saw all that stuff crammed into the base page...
Rice Flour Cookies