Ok, so something like this?
Code:
;LogClassObject would be an object of a class which implements the "Log interface"
Log_write(LogClassObject, Text)
{
ClassName := Class_getClassName(LogClassObject)
return %CLassName%_write(LogClassObject, Text)
}
If so, that's already possible. If you want to build "interfaces", go ahead. I will gladly distribute any interfaces you (or anyone else) makes with the Class library (if you'll let me, of course). This would allow standardizing certain functionality (like logging).
If you didn't care for a "interface check", then nothing needs to be tweaked. If you would want a check - verify the inputted object actually implements the interface, I would need to tweak the code a little (add interfaces to the class option). Additionally, I would add a function Class_implementsInterface(ClassObject, interface). It would return the object's class name if the object implemented the interface, and the empty string if not. Of course if ClassObject is NULL (0 or blank), the function would return the empty string as well
So, this tweaked version would be:
Code:
;LogClassObject would be an object of a class which implements the "Log interface"
Log_write(LogClassObject, Text)
{
if ClassName := Class_implementsInterface(LogClassObject, "Log")
return %ClassName%_write(LogClassObject, Text)
}
Then you would have MyLogClass.
Code:
MyLogClass_initClass()
{
;specify Class options in paretheses
;the interfaces would be a comma-delimited list starting after the semi-colon
static ClassName := "MyLogClass(Cloneable;Log,AnotherInterface)"
;or this, but it would waste memory (a small bit, granted)
static ClassName := "MyLogClass(Cloneable) implements (Log,AnotherInterface)"
return &ClassName
}
As a note, Log_write would call the "write" function for the class object (regardless what class it was). So, there is no need to register, I think. Or did you mean something else?
_________________
As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the
Class Library. Check out
my scripts.