Objective-D, reflective programming, dynamic typing
Michel Fortin
michel.fortin at michelf.com
Fri Apr 3 02:23:12 PDT 2009
On 2009-04-02 14:32:48 -0400, Steve Teale <steve.teale at britseyeview.com> said:
> Could you please give a three or four line example of what it is you
> want to achieve.
What Eljay wants to be able to do is this:
1. dynamically add message responders to dynamic objects
2. dynamically add message responders to dynamic classes, which would applies
3. capability to add override existing message responders
4. he want classes to be represented by singleton object factories used
to instanciate instances
Basically, he want to reimplement Objective-C in D, or so it looks like
(although Objective-C doesn't have 1), unless I'm missreading his
intent.
In his example he creates a base class called "Id", which is the root
for dynamic objects and has a "perform" method which is called whenever
you want to pass a message.
At that point he uses a switch statement in the derived class to decide
how to handle the message. Since he said earlier that the idea was to
use a hash table (to make things extendable at runtime), I guess
message handling is the point of his example. So it must be message
calling. Passing a message that looks like this in Objective-C:
[obj addWithA:5 withB:3];
would work something like this with his proposed system:
msg["@"] = "add"; // Just using "add", but could have been "addWithA:withB:"
msg["a"] = "5";
msg["b"] = "3";
obj.perform(msg);
- - -
And now, if I can put up my own suggestion, I'd suggest he tries with this:
obj.perform("add", 5, 3);
which could be implemented with a D-style variadic function, see:
<http://www.digitalmars.com/d/2.0/function.html#variadic>
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list