Properties transfer between instances of different classes, without subclassing

P

Pierre

Folks,
I'm pretty new to OOP, so I still have problems with inheritance and
delegation.
I defined 2 Numeric MaskedArray subclasses, as:

class Temp(MA,object):
def __init__(self,data):
self = MA.__init__(self,data)
cold = property(fget lambda self:masked_where(self<10,self)
warm = property(fget lambda self:masked_where(self>20,self)

class Tabl(MA,object):
def __init__(self,vector)
self.vector=vector
tabl = apply_processing_functions_to(vector)
self = MA.__init__(self,tabl)

where 'data' and 'vector' are themselves masked arrays.

I'd like to add the properties of the argument of an instance of Tabl
to this instance, only if the properties are not already defined.
For example, I create an instance of 'Temp' (say, 'tempv'), and
instance of 'Tabl' (say 'tablv'), this latter initialized with the
former.
v = arange(5,26)
tempv = Temp(v)
tabv = tabulated(tempv)

Ideally, 'tabv.cold' would give me 'tabv', masked where the values are
<10.
I don't want to make 'Tabl' a subclass of 'Temp'. I'd like to use it
more generically, so that when I define a 3rd class 'Color', I could
initiate 'Tabv' with an instance of 'Color', accessing the 'Color'
properties without the 'Temp' properties.

In short, I want to pass the properties of an instance attribute to the
instance...

Any ideas/comments will be welcome
 
H

Heiko Wundram

Pierre said:
Ideally, 'tabv.cold' would give me 'tabv', masked where the values are
<10.
I don't want to make 'Tabl' a subclass of 'Temp'. I'd like to use it
more generically, so that when I define a 3rd class 'Color', I could
initiate 'Tabv' with an instance of 'Color', accessing the 'Color'
properties without the 'Temp' properties.

I guess interfaces could make your day:

http://www.zope.org/Products/ZopeInterface

--- Heiko.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top