Page 1 of 1

Override Method

Posted: Tue Nov 05, 2019 9:17 am
by Natter
In my program, I replace the class method with my function.
Override Method AAA In Class BBB With MyFnc
Sometimes as the program progresses, I need to restore the standard implementation of the method. Can this be done ?

Re: Override Method

Posted: Tue Nov 05, 2019 11:56 am
by cnavarro
I think in this case it is better to use an EXTEND CLASS and not an OVERRIDE

Re: Override Method

Posted: Tue Nov 05, 2019 12:10 pm
by Natter
Thanks. But I think it's about the same thing

Re: Override Method

Posted: Tue Nov 05, 2019 3:23 pm
by AntoninoP
If you extend the class, you still call the base method using super operator

Code: Select all

#include <hbclass.ch>

class Base
   Method Func1() INLINE QOut("func1 of Base")
endclass

class Derived INHERIT Base
   Method Func1() INLINE QOut("func1 of Derived")
endclass

proc main()
   LOCAL obj := Derived():New()
   obj:Func1()
   obj:Super:Func1()
 
Result:

Code: Select all

func1 of Derived
func1 of Base