xsharp.eu • Overwriting hidden methods: X# vs VO
Page 1 of 1

Overwriting hidden methods: X# vs VO

Posted: Fri Mar 10, 2023 12:21 pm
by stefan.ungemach
The following Code

class MySuperClass
constructor
self:_setup()
hidden method _setup()
Safedebout32("mysuperclass",classname(self))
return
end class

class MySubClass inherit MySuperClass
hidden method _setup()
Safedebout32("mysubclass",classname(self))
return
end class

function TestCode() as usual clipper
local o as MySubClass

o := MySubClass{}
return

arrives at the green Line in VO and at the red line in X#. Do we really need to refactor all these occurences or is there some switch to enable VO-like behaviour in this case?

P.S.: If I omit the HIDDEN statement the behaviour is the same in both languages.

Overwriting hidden methods: X# vs VO

Posted: Fri Mar 10, 2023 3:47 pm
by Chris
Hi Stefan,

I think that's a bug in VO. By definition a HIDDEN (or PRIVATE as is usually called in .Net) method is only visible in the same class that it is declared in and completely invisible from anywhere else, including subclasses, so it cannot be called from the child constructor. Why had you defined the methods as HIDDEN, maybe you intended to define them as PROTECTED?

(not blaming you, I know that due to its very sloppy compiler VO allowed a lot of things to compile and work at runtime in a way that they never should had. X# revealed a lot of similar issues in my VO code, and everybody else's basically)

Overwriting hidden methods: X# vs VO

Posted: Sat Mar 11, 2023 6:57 am
by robert
Stefan,
In VO all methods are virtual. Apparently this means that you can override a hidden method.
In .Net private methods are never virtual (because they cannot be overwritten in subclasses).

Robert

Overwriting hidden methods: X# vs VO

Posted: Sat Mar 11, 2023 7:12 am
by stefan.ungemach
Thanks for clarifying. Unfortunately this special construct is Part of one of our most used design patterns which means that we should probably remote all our "hidden" Statements in Vo before continuing the migration...

Overwriting hidden methods: X# vs VO

Posted: Sat Mar 11, 2023 7:49 am
by VR
Instead of removing the Hidden Modifier, you could consider replacing it with the Proteced modifier.

Protected methods can be overridden but are only visible to class and all inherited classes but as hidden methods, they can not be called from other classes.

Volkmar