Subclassing and attribute methods

This is a discussion on Subclassing and attribute methods within the REXX forums in Programming Languages category; Hi All, Is there a limitation whereby a subclass cannot use attribute methods from the parent or is there a trick I can't find? My results return a non-initialised var, i.e., an uppercase method name. /* */ one = .one~new two = .two~new ::class one ::method one attribute ::method two return 'hello' ::method init self~one = 'hello' say self~one ::class two subclass one ::method init say self~one say self~two /* output */ hello ONE hello IBM Object Rexx 2.1.3 Phil ----...

Go Back   Application Development Forum > Programming Languages > REXX

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 07-30-2008, 04:51 AM
Phil
Guest
 
Default Subclassing and attribute methods

Hi All,
Is there a limitation whereby a subclass cannot use attribute methods from
the parent or is there a trick I can't find? My results return a
non-initialised var, i.e., an uppercase method name.

/* */
one = .one~new
two = .two~new

::class one

::method one attribute

::method two
return 'hello'

::method init
self~one = 'hello'
say self~one

::class two subclass one

::method init
say self~one
say self~two

/* output */
hello
ONE
hello

IBM Object Rexx 2.1.3

Phil
----


Reply With Quote
  #2  
Old 07-30-2008, 05:03 AM
rony
Guest
 
Default Re: Subclassing and attribute methods



Phil wrote:
> Hi All,
> Is there a limitation whereby a subclass cannot use attribute methods from
> the parent or is there a trick I can't find? My results return a
> non-initialised var, i.e., an uppercase method name.
>
> /* */
> one = .one~new
> two = .two~new
>
> ::class one
>
> ::method one attribute
>
> ::method two
> return 'hello'
>
> ::method init
> self~one = 'hello'
> say self~one
>
> ::class two subclass one
>
> ::method init
> say self~one
> say self~two
>
> /* output */
> hello
> ONE
> hello
>
> IBM Object Rexx 2.1.3


Firstly, you should upgrade to ooRexx 3.2.0 ASAP, which is newer and stabler than IBM Object Rexx,
from which sources ooRexx has evolved (http://www.ooRexx.org).

Secondly, you need to make sure in your subclass, that the superclass is able to run its
initialization method:

/* */
one = .one~new
two = .two~new

::class one

::method one attribute

::method two
return 'hello'

::method init
self~one = 'hello'
say self~one

::class two subclass one

::method init
self~init:super -- <-- let superclass' initialize
say self~one
say self~two

The output then:

hello
hello
hello
hello

HTH,

---rony

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 08:43 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.