Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Currently in a debate at work and I cannot fathom why someone would intentionally avoid Inheritance with Master Pages.

For reference here is the project setup:

  • BaseProject
    • MainMasterPage
      • SomeEvent
  • SiteProject
    • SiteMasterPage
      • nested MainMasterPage
  • OtherSiteProject
    • MainMasterPage (from BaseProject)

The debate came up because some code in BaseProject needs to know about "SomeEvent". With the setup above, the code in BaseProject needs to call this.Master.Master. That same code in BaseProject also applies to OtherSiteProject which is just accessed as this.Master.

SiteMasterPage has no code differences, only HTML differences.
If SiteMasterPage Inherits MainMasterPage rather than Nests it, then all code is valid as this.Master.

Can anyone think of a reason why to use a Nested Master Page here instead of an Inherited one?

share|improve this question
    
Check out codeproject.com/Articles/18641/… –  The Muffin Man Mar 27 '12 at 20:37
    
@Nick : Yeah, already ran across that. So far the only reason is some problem someone had in 2007 that no one ever bothered to figure out? :P –  James P. Wright Mar 27 '12 at 20:56
    
I am going to guess that those HTML differences are why it was separated out. Since the whole idea of MP inheritance is to support Visual Inheritance, then I'm guessing that there either were actual or imagined (either concurrent or future) issues with the layout. –  Joshua Drake Mar 30 '12 at 19:29

1 Answer 1

No.

First, I'd recommend using the MVP design pattern for webforms. Separate the logic that manipulates the view from the logic that manipulates the data model (View Logic, Business Logic). Put all your logic in classes instead of in the code-behind. Also, decide which works best for you: Passive View or Supervising Controller.

SiteMasterPage has no code differences, only HTML differences.

Extract all the logic into a separate class: [Description]MasterPage such as class DefaultMasterPage. Each MasterPage would inherit this class. This way you're not duplicating code. The only differences will be with the html in the MasterPages.

If the logic begins to diverge you now have the option to Inherit and Override functionality (still in separate classes, not in the code-behind).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.