AutoHotkey Community

It is currently May 26th, 2012, 4:04 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 259 posts ]  Go to page Previous  1 ... 14, 15, 16, 17, 18
Author Message
 Post subject:
PostPosted: April 9th, 2009, 12:06 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 12th, 2009, 8:55 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 12th, 2009, 10:40 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
That sounds fine; I've never have, and never plan to, use that term in my code. Sounds like interfaces are almost ready. Exciting :)

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 11th, 2010, 3:19 am 
does this require AHK_L? how does it compare/contrast against AHK_L objects?


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 259 posts ]  Go to page Previous  1 ... 14, 15, 16, 17, 18

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group