[Zope-CMF] How to mixin classes, was: A modest proposal to add a Unique ID to all content/folder objects in CMF

Grégoire Weber gregoire.weber@switzerland.org
Thu, 12 Sep 2002 14:37:17 +0200


Hi all,

it seems that I found the answer myself on how I would do it.
But is this the usual way people mix in classes in CMF?

What happens if more than one Product mixes in classes
which override original methods? seems to look bad :-(

See especially lines starting with comments #####:

>>> class Base:
...   def base_meth(self):
...     print 'called Base.meth'
...
>>> class Document(Base):
...   def doc_meth(self):
...     print 'called Document.doc_meth'
...   def doc_meth2(self):
...     print 'called Document.doc_meth2'
...
>>> class Mixin:
...   def mix_meth(self):
...     print 'called Mixin.mix_meth'
...   def doc_meth2(self):
...     print 'called Mixin.doc_meth2 (overridden the Documents one)'
...
>>> dir(Base)
['__doc__', '__module__', 'base_meth']
>>> dir(Document)
['__doc__', '__module__', 'base_meth', 'doc_meth', 'doc_meth2']
>>> dir(Mixin)
['__doc__', '__module__', 'doc_meth2', 'mix_meth']
>>>
>>> ##### mixin class 'Mixin' into class 'Document'
>>> class Document(Mixin, Document):
...   pass
...
>>> dir(Document)
['__doc__', '__module__', 'base_meth', 'doc_meth', 'doc_meth2', 'mix_meth']
>>>
>>> doc=Document()
>>> doc.base_meth()
called Base.meth
>>> doc.mix_meth()
called Mixin.mix_meth
>>> doc.doc_meth()
called Document.doc_meth
>>> ##### mix in class 'Mixin' overrides the 'Document' classes method=
 'doc_meth2'
>>> doc.doc_meth2()
called Mixin.doc_meth2 (overridden the Documents one)
>>>

Thanks in advance, Greg

At 13:31 12.09.2002 +0200, Grégoire Weber wrote:
>Hi Tim, 
>hi all,
>
>I have to mixin some behaviour to existing objects also and I saw your
>example below, which I understand how it works.
>
>What I do not understand is how mixing in a class exactly works 
>(what I have to do):
>
>   How do you mix in the UniqueId class exactly into CMFCore.PortalContent?
>   By hotfixing CMFCore.PortalContent?
>   How do you get the ZID method seen by the catalog?
>
>   Is there an example (Product) out there (didn't find How-Tos and hints=
 
>   on zope-cmf@zope.org), where I can analyze the code?
>
>Greetings, Greg

_____________________________________
Grégoire Weber
Rigistr. 31
CH-8006 Zürich
Switzerland
phone:  +41-(0)1-361 66 11
mobile: +41-(0)79-44 11 457
mailto:gregoire.weber@switzerland.org