[Zope-dev] A product class that subclasses another product

Howard Clinton Shaw III shawh@sths.org
Mon, 24 May 1999 09:07:29 -0500


On Sun, 23 May 1999, Michel Pelletier wrote:
> > -----Original Message-----
> > From: Itai Tavor [mailto:itavor@vic.bigpond.net.au]
> > Sent: Wednesday, May 19, 1999 11:10 PM
> > To: zope-dev@zope.org
> > Subject: [Zope-dev] A product class that subclasses another product
> > 
> > 
> > Hi,
> > 
> > I'm building several products that need to share several 
> > common attributes
> > and methods, so I put those is a product ('Master') that the 
> > other products
> > subclass.
> > 
> > My problem is that I can't figure out how to call methods in 
> > the Master
> > class and how to access its attributes.
> > 
> > Very simplified, it looks something like this:
> > 
> > class Master:
> > 
> >     def __init__(self, status, REQUEST=None):
> >         """Initialize a new master object"""
> >         self.status = status
> > 
> >     def manage_edit(self, status, REQUEST=None):
> >         """Change object properties"""
> >         self.status = status
> > 
> >     def Visible(self):
> >         """Check if object's status is 'visible'"""
> >         if self.status == 4:
> >             return 1
> >         return 0
> > 
> > 
> > from Products.Master import Master
> > class Foo(Master):
> > 
> >     meta_type = 'Foo'
> >     id = ''
> >     icon = 'misc_/Foo/icon'
> > 
> >     def __init__(self, id, title, status, REQUEST):
> >         """Create a new article entry"""
> >         self.id            = id
> >         self.title         = title
> >         Master(status, REQUEST)
This should be Master.__init__(status, REQUEST), otherwise you are creating and discarding a Master instance.
> > 
> >     def manage_edit(self, title, status, REQUEST=None):
> >         """Change information for object"""
> >         self.title  = title
> >         Master.manage_edit(status, REQUEST)
This should work. If it doesn't, something very strange is going on. (which might be occasioned by your peculiar
syntactic initialization above.)
> > 
> > 
> > The above simply fails to find the Master methods. I tried
> > Master.Master.manage_edit, as well as doing self.master = 
> > Master(status,
> > REQUEST) in __init__ and then master.manage_edit(...), but 
> > neither worked.
> > Also, is it possible to access attributes of the Master 
> > class, or do I need
> > to define methods in Master to return attributes?
It should be possible to access attributes directly, it violates the principle of encapsulation,
but what the hey... Oh, wait a minute, I think I might have it.
I think you need to manually pass in 'self'!! 
try Master.__init__(self, status, REQUEST)
and 
Master.manage_edit(self, status, REQUEST)
I think that should do it.

What you are doing here, is not calling attributes of your base class instance, because there is
no such instance. Rather, you are manually calling methods of your base CLASS (not instance), and so
must pass in self, since they are 'unbound' methods. Have fun!
> > 
> 
> Your question could best be answered on the Python mailing list, as this
> is a Python question (in the context of Zope).  I suspect Computed
> attributes could help you out here in ExtensionClasses, but there may be
> a Python mechanism I am unaware of that can solve the problem without
> using Computed attributes.
> 
> The Python list can be found at http://www.python.org
> 
> -Michel
> 
> 
> > Thanks
> > Itai Tavor
> > --
> > Itai Tavor                      -- "Je sautille, donc je suis."    --
> > itavor@vic.bigpond.net.au       --               - Kermit the Frog --
> > --                                                                 --
> > -- "Every day, once a day, give yourself a present"  - Dale Cooper --
> > 
> > 
> > _______________________________________________
> > Zope-Dev maillist  -  Zope-Dev@zope.org
> > http://www.zope.org/mailman/listinfo/zope-dev
> > 
> > (For non-developer, user-level issues, use the companion list,
> > zope@zope.org, http://www.zope.org/mailman/listinfo/zope )
> > 
> 
> _______________________________________________
> Zope-Dev maillist  -  Zope-Dev@zope.org
> http://www.zope.org/mailman/listinfo/zope-dev
> 
> (For non-developer, user-level issues, use the companion list,
> zope@zope.org, http://www.zope.org/mailman/listinfo/zope )
--
Howard Clinton Shaw III - Grum
St. Thomas High School
#include "disclaimer.h"