AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Class library (OOP) - Wish list / Bug reports thread
Goto page Previous  1, 2, 3 ... 16, 17, 18
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
animeaime



Joined: 04 Nov 2008
Posts: 1046

PostPosted: Thu Apr 09, 2009 12:06 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
animeaime



Joined: 04 Nov 2008
Posts: 1046

PostPosted: Sun Apr 12, 2009 8:55 pm    Post subject: Reply with quote

OK. The design for interfaces is done, but there's one final question. As posted in my wish list thread, A_ParamCount - to retrieve the number of PASSED parameters, there is no way to detect how many parameters were ACTUALLY passed to a function. Therefore, in the meanwhile, I'm going to use a "reserved" value to detect when an optional parameter wasn't passed.

The problem is that this reserved value couldn't be used as an actual parameter, so the empty string, the obvious choice, isn't an option. For if the empty string was the "reserved string", it couldn't be used as a parameter. I was thinking "C1@s5" (L33T Class). This value should be never been needed (which is a requirement of the "reserved value"), and it's short, so functions with several optional parameters won't have "long" function signatures. Note: this value would be case-sensitive (for performance).


As a reserved value, if passed, the code would think that the parameter (and thus the ones after), were not passed. So, before uploading the latest version of the Class library (with interfaces), I wanted to verify that no one had objections to "C1@s5" being used as the "reserved value".

An example of it's use:

Code:
Car_getPurchaseDate(CarObject, TimeFormat = "C1@s5")
{
    return Class_call(A_ThisFunc, CarObject, TimeFormat)
}


Note: the above function is all that is required to add a "getPurchaseDate" function to the Car interface. The Class_call function handles the details. Because the "reserved value" is used for the default value, the default value in the implementing class would be used when calling the Interface function.
_________________
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.
Back to top
View user's profile Send private message Send e-mail
bmcclure



Joined: 24 Nov 2007
Posts: 766

PostPosted: Sun Apr 12, 2009 10:40 pm    Post subject: Reply with quote

That sounds fine; I've never have, and never plan to, use that term in my code. Sounds like interfaces are almost ready. Exciting Smile
_________________
Ben

My Trac projects
My Wiki
[Broken] - My music
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3 ... 16, 17, 18
Page 18 of 18

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group