[Gambas-user] About OOP features missing on Gambas

Tobias Boege taboege at gmail.com
Fri Jun 14 12:40:36 CEST 2019

On Tue, 11 Jun 2019, Yeshua Rodas wrote:
> Thank you. All is more clear for me now.
> However, I'm facing an issue that I'm not sure how to handle it.
> I have a basic class with a method:
> Public Function doSomething(param as SomeBaseClass) as String
>   ' Some stuff
> End
> And a derivated class that I need to call some specialized method
> Public Function doSomething(param as SomeDerivatedClass) as String
>   ' Some stuff
>   param.childMethod()
>   ' More stuff
> End
> But this rise "Symbol is badly overridden" error.
> I think that on overriding would be useful to override the type for an
> inherited type. The actual constraint model is squeezing my brain.

Allowing that seems sensible to me. You'll have to get Benoît's attention
to have it implemented though.

But note that Gambas does not have polymorphic methods, so with the above
you will essentially forbid someone to use the derived class's doSomething
like they could with the parent class, because the signature is irrevocably
more constrained. To me, this seems like a violation of Liskov's substitution
principle, which you may care about or not.

Also note that you can put an object of type B into a variable typed A
*and get it out again* into a variable typed B, provided that the actual
type of the object is B and B inherits A. An object does not lose its
"true type" by being placed in a typed variable. A variable's type acts
mostly like a method lookup table for the contained object, which you
can switch out as long as they are compatible via inheritance.

  Public Function doSomething(param As SomeBaseClass) As String
    Dim der As SomeDerivatedClass = param

in SomeDerivatedClass will work right now without raising the
"badly overridden" error. Put in a Try and a call to Super.doSomething
and you have manually constructed a method that is polymorphic along
class lineage. The other solution that works right now would be to name
the new method differently.


"There's an old saying: Don't change anything... ever!" -- Mr. Monk

More information about the User mailing list