What about Extendable and CallExtension?

BlitzMax Forums/BlitzMax Programming/What about Extendable and CallExtension?

Fabian.(Posted 2005) [#1]
I'd suggest to add two new keywords you can use like this:
Strict

Print New T1.GetName ( ) 'prints "T1"
Print New T2.GetName ( ) 'prints "T1 extended by T2"

Type T1
  Method GetName$ ( ) Extendable
    Return "T1" + CallExtension ( )
  EndMethod
EndType

Type T2
  Method GetName$ ( )
    Return " extended by T2"
  EndMethod
EndType

Sometimes I want to have a method which can't be overwritten, but be extended like Method New() or Method Delete().
So I'd suggest to add a keyword "Extendable" which can be used like "Abstract" or "Final" with the limit only to use it with methods.
This keyword says you can 'overwrite' this method, but your method will not be called instead of the super method, it'll be call when super method calls "CallExtension".
CallExtension has same params and return value like the method calling it and CallExtension can only be called from an extendable method.
This could also be used for event handlers like this:
...

Type TApplication
  ...

  Method OnEvent ( Event:TEvent ) Extendable
    Select Event.id
      Case EVENT_APPTERMINATE
        End
      Case ...
        ...
      Default
        Return CallExtension ( Event ) 'All methods overwriting this one cannot receive an appterminate event.
    EndMethod
  EndMethod
EndType


How do think about it?


Warpy(Posted 2005) [#2]
what's wrong with calling super.mymethod() and doing it the other way round? For your event handler...




Fabian.(Posted 2005) [#3]
Because I can't be sure that the user of my class calls super.mymethod() at all.


Warpy(Posted 2005) [#4]
hmmm...


But yeah, I see what you mean.