Suppose I have two or more
UserControl implementations with vastly different implementations but near identical code-behind. One strategy to avoid code duplication is as follows:
- Change each
UserControlto inherit from a new abstract class,
- Move all of the codebehind from each
AwesomeUserControldoes not have an ascx file).
- Add abstract getters to
AwesomeUserControlfor any controls from the ascx file of the original UserControls.
- Implement these getters in each
This strategy works extremely well and is easy to maintain. However, it also introduces stupid scaffolding code; every new implementation of
AwesomeUserControl has a bunch of getters to hook
AwesomeUserControl the UI elements inside of the new control. Any time I find myself using a strategy which requires copy-pasted scaffolding code, I worry that I am doing something wrong. Though it does have a nice effect of failing to compile if the UI elements are missing (as opposed to skipping the scaffolding code in favor of reflection and required naming).
Is this use of inheritance reasonable?