realbasic-nug
[Top] [All Lists]

Re: Stupid question: instantiating classes at runtime--what about method

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Stupid question: instantiating classes at runtime--what about methods
From: Andy Dent <dent at oofile dot com dot au>
Date: Mon, 31 Dec 2007 14:52:36 +0900
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <45a1b53e0712301802i69eef3asc37b33d29ea054be at mail dot gmail dot com>
Again, I'd like to offer a little clarification.

On 31/12/2007, at 11:02 AM, Wade Maxfield wrote:

>    It is not intuitively easy to change what code a method calls in
> C++ at run time either, but it can be done by using pointers.
>
>    in C/C++, you can have pointers to functions.  You can then put
> these pointers to functions in classes as properties, and then have
> class methods call through the function pointers.

This is basically the Strategy design pattern - you are designing your  
methods up-front to have a replaceable Strategy which is invoked via  
the pointer.

In Python, Lua and other languages you can replace the method for a  
given object without any design consideration up-front. This is the  
equivalent of hacking the vtable for a C++ object.

Any language which allows you to do evaluation of arbitrary strings  
allows you to implement pointers as per Wade's description. I've used  
that to build an OO framework with polymorphism in FoxBase and 4th  
Dimension. Note that RBScript does NOT allow evaluation of arbitrary  
strings - you're in a "sandbox" imposed by the context object you  
supply.


>   I think that RB can do close to this using delegates, I just don't
> have my mind wrapped around delegates yet.

If you have a C++ background, delegates are a combination of a pointer  
to a member function and the object pointer required to use that  
member function.

Yes, delegates allow for such redirection BUT they do so by implying a  
destination object that is handling the call, not just code. Prior to  
delegates, I would achieve the same thing using interfaces.

Happy New Year (nearly) to all

Andy
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>