I was thinking of a new meta-function that is called every time the
extends keyword is used, something like:
Code: Select all
class A
{
__Extend(SubClass)
{
/* You can do the ff here
- check if the proper methods/properties were defined/overrriden
- store a reference to the subclass
- initialize some class properties
- throw Exception if a private method is overrriden
- etc.
*/
}
}
; using the 'extends' keyword, SuperClass.__Extend() is
; called(maybe before the auto-execute section) passing
; SubClass as argument
;
; or alternatively, SuperClass.__Extend.Call(SubClass) - 'this' is now a reference to the SubClass
class B extends A
{
}
Currently, something similar can be achieved using
Instance variables, however,
new must be used. Or another option is to instruct those who want to extend the class to declare a
Static/Class variable and have it call a method defined in the base class. The former requires the subclass to be instantiated while the latter requires extra work form the user's end and can easily be neglected. Another way is to scan the script for class declaration(s) - this wouldn't work if the script was launched dynamically via
AutoHotkey.exe *.
Unless there is some undocumented way to achieve this.