[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inheritance query



"J.D. Smith" wrote:
> 
> Bernard Puc wrote:
> >
> > Hello
> >
> >         For the object programming gurus:  I'm creating a class called data.
> > I'm then creating subclasses of data called type1, type2, etc.  The
> > type1 class inherits the data class attributes.  Now, is it possible to
> > inherit, lets say, the data::INIT method and somehow add to it?  Or, do
> > I have to write an entirely new INIT method for type1 class which
> > incorporates the statements in the data::INIT method?
> 
> By default, all methods are inherited.  To add to the method, you need to "chain
> up" to the superclass, like this:
> 
> function SubClass::Init,_EXTRA=e
>    if (self->SuperClass::Init(_EXTRA=e) ne 1) then return,0
>    ;;; do more stuff
>    return,1
> end
> 

One more tip:  make good use of the _REF_EXTRA mechanism for chaining up to
methods which should return something:

pro SubClass::GetProperty,VALUE=val,_REF_EXTRA=e
	val=self.value
	SuperClass::GetProperty,_EXTRA=e
end

This allows the SuperClass's GetProperty Method to put things into variables for
return (like properties of the SuperClass, which aren't always just data
member!), impossible with the _EXTRA mechanism.

JD

-- 
 J.D. Smith                             |*|      WORK: (607) 255-5842    
 Cornell University Dept. of Astronomy  |*|            (607) 255-6263
 304 Space Sciences Bldg.               |*|       FAX: (607) 255-5875 
 Ithaca, NY 14853                       |*|