So you have an interface:
from zope.interface import Interface, Attribute
name = Attribute("""The name of the fruit""")
Ok, it's simple. Now you write a class that implements this, still simple.
def __init__(self, name):
self.name = name
Pretty good. You can store that in an object database like ZODB if you like, but we are going to think how to view it.
A view (in Zope terminology) is something that adapts (multi-adapts) a "context" and a "request". We don't really understand what a "context" is, so we are going to call it an "object". A request can be something like "edit" or "view".
So of course we need an interface for views to adhere to, and an interface for a request to adhere to. This is where interfaces stop being documentation niceties, and start being implementation nasties.
"""Display what needs displaying"""
user = Attribute("""The user that made the request""")
So imagine we implement a simple view (now remember this is nothing to do with a web application). The view will display Fruit objects.
from zope.component import adapts, provideAdapter, getMultiAdapter
def __init__(self, fruit):
self._fruit = fruit
# not forgetting to register the adapter with zope.component
And also a request implementation that does nothing
user = None
And we are ready to go:
view = getMultiAdapter((Fruit('banana'), ViewRequest()), IView)