bmmcclure wrote:
My main question about the difference is related to Class vs Interface. For instance, right now I have things like an Error class and a Log class which I am using in most of my classes in some way or another.
I'd ultimately like to use inheritance with them, but I think things like that would work fine as interfaces, right?
In what way do you use the Log and Error Class? For the Class library, an interface will mimic an abstract class (for the most part). For example, you can implement functions in the base class (if you wish), or leave it up to the implementing class. As an abstract class, you won't be able to create objects of that class. Instead, you define a class (e.g. a MyLog class) which would implement the interface, and you could then create MyLog objects.
You ARE allowed getters and setters in an interface - they are only functions. However, you can't define their type or index - this is because an interface CANNOT have data. Instead, the implementing class would be responsible for the details.
Under this setup. You could define a "writeLine" function like this.
Code:
Log_writeLine(LogObject, Text)
{
;return the log's data
logData := Log_getData(LogObject)
;static function Log_addLine would add the line
Log_addLine(logData, Text)
}
In this case, Log_getData would be a getter function which an implementing class would implement - it would return the data for the log file (e.g. a Vector of Strings or a Vector of LogLines - a Class you create). Likewise, Log_addLine would be a static function which would be implemented - this would add the line of text to the specified log file. Note: the above function works regardless how these two functions are implemented. It is up to the implementing class to implement HOW to add the line of text.
Also, notice how static functions can be part of an interface. Since AHK isn't OOP, EVERY function is technically static. This differs from traditional interfaces (e.g. in Java) where static functions cannot be defined.
_________________
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.