If you use Cheetah, please support the project and register by clicking here:

14.2 Containment vs Inheritance

Because Cheetah's core is flexible, there are many ways to integrate it with Webware servlets. There are two broad strategies: the Inheritance approach and the Containment approach. The difference is that in the Inheritance approach, your template object is the servlet, whereas in the Containment approach, the servlet is not a template but merely uses template(s) for portion(s) of its work.

The Inheritance approach is recommended for new sites because it's simpler, and because it scales well for large sites with a site->section->subsection->servlet hierarchy. The Containment approach is better for existing servlets that you don't want to restructure. For instance, you can use the Containment approach to embed a discussion-forum table at the bottom of a web page.

However, most people who use Cheetah extensively seem to prefer the Inheritance approach because even the most analytical servlet needs to produce some output, and it has to fit the site's look and feel anyway, so you may as well use a template-servlet as the place to put the output. Especially since it's so easy to add a template-servlet to a site once the framework is established. So we recommend you at least evaluate the effort that would be required to convert your site framework to template superclasses as described below, vs the greater flexibility and manageability it might give the site over the long term. You don't necessarily have to convert all your existing servlets right away: just build common site templates that are visually and behaviorally compatible with your specification, and use them for new servlets. Existing servlets can be converted later, if at all.

Edmund Liam is preparing a section on a hybrid approach, in which the servlet is not a template, but still calls template(s) in an inheritance chain to produce the output. The advantage of this approach is that you aren't dealing with Template methods and Webware methods in the same object.

If you use Cheetah, please support the project and register by clicking here: