469,343 Members | 5,279 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

Properties transfer between instances of different classes, without subclassing

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

Dec 10 '05 #1
1 1235
Pierre wrote:
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.
Dec 10 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Kerry Neilson | last post: by
10 posts views Thread by Martin Miller | last post: by
90 posts views Thread by Ben Finney | last post: by
17 posts views Thread by David C. Ullrich | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.