xsharp.eu • Avoiding obligatory SUPER constructor call
Page 1 of 1

Avoiding obligatory SUPER constructor call

Posted: Tue May 12, 2020 3:28 pm
by Serggio
Is there any way to avoid calling SUPER constructor in a constructor of an inherited class?
There are situations when SUPER constructor is of totally different nature and simply may not be called and should be completely overriden.
I know, that's not very OOP-ish and one should use interface or something like that to untie that properly.
But. The question I'm asking is not just the point of mere interest but a, so to say, decision input, because refactoring price and changing OOP-model seem to be quite costly.

Avoiding obligatory SUPER constructor call

Posted: Tue May 12, 2020 6:51 pm
by Chris
Hi Serggio,

Just use something like that in your child's class constructor:

Code: Select all

CONSTRUCTOR()
	IF FALSE
		SUPER()
	END IF
	// .normal code
RETURN

the compiler will detect you are handling SUPER() yourself and will not add implicitly code to call it. But please just don't show the above X# trick to any c# guy, because they will sue us for breaking every OOP law available :)

Avoiding obligatory SUPER constructor call

Posted: Tue May 12, 2020 7:19 pm
by Serggio
Thank you very much, Chris! That should save me a lot of time.