Implementation Alternatives Question
I'm working on a site to display news articles. There are a handful of different "sections" to the site, each with it's own look. For the most part they look the same but there are subtle differences. A title or graphic might change, some subnavigation might be different, etc. As currently implemented, I've just defined Folders which contain a set of DTMLMethods which define the layout. After doing two or three I see that the content of these folders is almost identical. I realize that I could factor out the common stuff and move it to the root folder, but I'm not thrilled with cluttering my root with stuff which is only applicable to a subset of lower elements. What I'm currently experimenting with is defining a ZClass for a "Content Viewer" folderish object. The ZClass would contain definitions for the common methods. The variability between looks can mostly be accomplished by using different property value settings for each individual ZClass instance. My current quandary is what to do when a property change isn't sufficient. If I were doing this in Smalltalk or Java, I would simply subclass my folder viewer and override any methods that I needed. I know that I can do something similar with ZClasses but I'm wondering if that is a good approach for Zope. Given what I want to do, I see three basic alternatives: 1. Move common functionality up to the root folder. 2. Define a ZClass and subclass with other ZClasses as necessary to get a combination of variability while obeying the "once and only once" rule of good OO programming. 3. Do the subclassing via Python and create a flat ZClass structure within Zope. Are there any other options? What are the pros and cons of each option? Any input would be helpful. Thanks. James W. Howe mailto:jwh@allencreek.com Allen Creek Software, Inc. pgpkey: http://ic.net/~jwh/pgpkey.html Ann Arbor, MI 48103
What I'm currently experimenting with is defining a ZClass for a "Content Viewer" folderish object. The ZClass would contain definitions for the common methods. The variability between looks can mostly be accomplished by using different property value settings for each individual ZClass instance. My current quandary is what to do when a property change isn't sufficient. If I were doing this in Smalltalk or Java, I would simply subclass my folder viewer and override any methods that I needed. I know that I can do something similar with ZClasses but I'm wondering if that is a good approach for Zope.
I did just that for two areas of my site. I subclassed Folder and created a ZClass called ArticleContainer. ArticleContainer has an index_html method that formats the page like this: * html_header (imported from site root) * header (imported from current folder) * table with articles on left (a tokens property set on a per ArticleContainer basis determines which subfolders articles get pulled out of) * sidebars (a list of tokens set on a per ArticleContainer basis; each token is looked up and called as a DTML Method to show on the right of the table) common sidebars are inside of the ArticleContainer ZClass (I'm not sure about this), but section-specific ones * close table * footer (imported from current folder) * html_footer (imported from site root) perhaps I should merge footer and html_footer, creating a footer that looks like: footer commands <dtml-var "html_footer.__call__(_,_.None)"> (ditto for header). Other than that, though, I like the delegation stuff. -- Stephen Pitts smpitts@midsouth.rr.com webmaster - http://www.mschess.org
participants (2)
-
James W. Howe -
Stephen Pitts