>>
Make the component a class that stands on its own. When the
component needs to interact with a page, session, etc then give it
access to those objects.
<<
Yes, this makes perfect sense but your Menu() implementation is one of many possible
which could implement an IMenu interface :
class IMenu(Interface.Base):
"""Implements a menu"""
def write(self,page):
"""writes output to the page"""
def add(self,item):
"""adds a new menu item"""
def remove(self,index):
"""delete the specified menu item"""
for instance, we could define a menu with fancy Javascript-events and you could swap
it in for your current Menu() instantiation :
self.menu = Menu()
becomes :
self.menu = FancyJSMenu()
and everything else works fine. But in fact I think you might want to do something
like :
self.menu = getSuitableMenuForThisBrowser(self.request)
(the idea is that it would pass you the best IMenu implementation you're browser can
cope with and that has been registered with the application).
My point is that as soon as you just say "just create an object to do it" you're
creating a interface definition that someone else has to match in order to swap your
components for theirs.
And I believe that is the point : Our own components means our own methods and that
makes it harder to use each-others stuff. Whether we use Zope-stype Interfaces or just
plain Python classes isn't the problem : The problem is agreeing on a single set of
methods that all implementations of a component adhere to.
- Ian Sparks.
-----Original Message-----
From: Jim Bucher [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 06, 2003 2:52 PM
To: [EMAIL PROTECTED]
Subject: [Webware-discuss] Components
I like the idea of using components for reusability. But interfaces,
inheritance and mixins seem to be a complex solution. How about doing it
this way. Make the component a class that stands on its own. When the
component needs to interact with a page, session, etc then give it
access to those objects. It seems to be simple. What do you think? Here
is a quick example.
##### Menu.py
class Menu:
items = [] # a list of ('URL name', 'menu name') tuples
def write(self, page):
page.writeln("<div class='menu'>")
for item in self.items:
page.writeln("<a href='%s'> %s </a>  " % item)
page.writeln("</div>")
def add(self, item):
self.items.append(item)
def remove(self, index):
self.items.pop(index)
##### SitePage.py
from WebKit.Page import Page
from Menu import Menu
class SitePage(Page):
def __init__(self):
Page.__init__(self)
self.createMenu()
def createMenu(self):
self.menu = Menu()
menu = self.menu
menu.add('Login','Login')
menu.add('Project','Select Project')
menu.add('Soil', 'Soils')
menu.add('Plant', 'Plants')
menu.add('PlantCommunity', 'Plant Communities')
menu.add('Grazer', 'Grazers / Preferences')
menu.add('GrazerPlan', 'Grazing Profiles')
menu.add('Run', 'Model Runs')
def writeBodyParts(self):
self.menu.write(self)
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger
for complex code. Debugging C/C++ programs can leave you feeling lost and
disoriented. TotalView can help you find your way. Available on major UNIX
and Linux platforms. Try it free. www.etnus.com
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss