Override Method

Override Method

Postby Natter » Tue Nov 05, 2019 9:17 am

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 ?
Natter
 
Posts: 1224
Joined: Mon May 14, 2007 9:49 am

Re: Override Method

Postby cnavarro » Tue Nov 05, 2019 11:56 am

I think in this case it is better to use an EXTEND CLASS and not an OVERRIDE
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Override Method

Postby Natter » Tue Nov 05, 2019 12:10 pm

Thanks. But I think it's about the same thing
Natter
 
Posts: 1224
Joined: Mon May 14, 2007 9:49 am

Re: Override Method

Postby AntoninoP » Tue Nov 05, 2019 3:23 pm

If you extend the class, you still call the base method using super operator
Code: Select all  Expand view  RUN
#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  Expand view  RUN

func1 of Derived
func1 of Base
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 51 guests