tags:

views:

255

answers:

1

I'm using Mako's inheritance features to factor out common page elements, like a header and footer, into a "base.mako" template. Page-specific controllers use their own templates, which inherit base.mako.

base.mako needs a set of variables -- for example, the name of the logged-on user goes in the header for all pages. However, it's the individual page controller that selects and renders the template, and is therefore responsible for passing variables to it.

I'd rather all of those page controllers not have to know what the base template needs in its context. What's a good way to establish the context for the base template in a situation like this?

Thanks in advance!

A: 

You have two OO design choices for your page controllers.

Common features can be handled two ways.

  • Inheritance. All page controllers are subclasses of a common class that provides the common attributes.

  • Delegation. All page controllers are part of a pipeline where some common process (either before or after the page controller) folds in the additional information.

You have to pick one.

S.Lott
When I first read your answer I thought I wanted more specific advice. Upon further contemplation I realized that what you've said is actually more helpful, requiring me to take a step back and think about the problem in more general terms. Thank you!
jgarbers
@jgarbers: Sorry for making you think, but you're having "The Standard Problem" of managing common features.
S.Lott