Reputation: 8168
Should I be using multiple base pages with inheritance or is there a better strategy?
Contrived Example:
Currently I have 20 webpages and they all use my base-page "BasePage".
ie.) Page1 : BasePage
BasePage provides functions:
Now I decide that 5 of my 20 webpages require the BasePage functions as well as 3 additional functions and a Page_Load():
Do I now create another base page like this:
MySecondBasePage : BasePage
and then put Function4(), Function5(), Function6() and Page_Load() in it?
Or is there a better/"proper" strategy to doing this? Should I be using classes?
Upvotes: 4
Views: 235
Reputation: 787
Yes, creating MySecondBasePage
which inherits from BasePage
seems to be the right way in your case.
Then, in the 5 "special" pages, you inherit MySecondBasePage
instead of BasePage
.
This is the proper class hierarchy for your situation.
Upvotes: 1
Reputation: 113322
Yes.
Inheritance is not just about re-use (since we have other ways to do that), but also about managing complexity. This is a nice simple hierarchy that (assuming your real names are a bit better than "SecondPageBase") will help make it clear what is happening where, and why.
Upvotes: 1