[Zope] Web pages as Object Classes

Johan Carlsson johanc at easypublisher.com
Mon Feb 2 05:40:33 EST 2004


Paolo Losi wrote:
> Hi all,
>     here you have another newbie :-)
> 
> I'm studying Zope and looking for a clever way
> to use all its power.
> 
> I've been using recently the quixote application server
> and using that framework I've been able to structure
> my sites as a collection of HTML pages classes.
> 
> The idea is to have an "abstract" superclass which
> defines the basic structure of the page:
> - look and feel (via css for example)
> - basic container structure (I get a menu on the left,
>   a login status on the right top...)
> 
> A very easy example just to get the idea could be:
> 
> class MySitePage():
>     def render(self):
>         self.header()
>         self.menu()
>         self.login_status()
>         self.content()
>         self.footer()
>     
> Each method must output HTML and can/must be specialized
> in subclasses...
> 
> The thing that I appreciate about this approch is
> the flexibility you get from inheritance.
> I try to go a little bit further that separation
> between content and presentation. I try to design
> presentation in a OO way...
> 
>  From what I've seen PTL is not flexible enough
> to implement this approach... am I wrong?
> Is it better to look into ZClasses?

There are better Design Patterns than inheritance for doing the same 
thing. (I am using a dekoration pattern myself where the dekor is a 
template with a number of views).

Zope it self uses the concept of run-time inheritance (e.g. acqusition).

Your base class would be your root-object, index_html in the root object
is the base implementation of render() and it can call header, menu,
login_status, content, footer. The sub-classes are object futher down
the hieracy and every thing can be overriden in it.
The problem with this approach is of course that implementation,
data and hierarcy gets mixed up in an unfortunate combination.

This problem has been taceled in many product, such as portal_skins (in 
CMF) or the template system in EasyPublisher or by proxy/repository 
implementations.

IMHO I think you would be better of understanding the power of Zope
first and than look at what archtecture/patterns would suit you.

That's my 25.cents anyway :-)

-- 
Johan Carlsson          Tel: + 46 8 31 24 94
Colliberty              Mob: + 46 70 558 25 24
Torsgatan 72            Email: johanc at easypublisher.com
SE-113 37 STOCKHOLM     Skype: colliberty





More information about the Zope mailing list