D versus Objective C Comparison
Nick Sabalausky
a at a.a
Sun Feb 1 12:14:23 PST 2009
"Jacob Carlborg" <doob at me.com> wrote in message
news:gm4fsm$kds$1 at digitalmars.com...
> Michel Fortin wrote:
>> On 2009-01-31 20:51:57 -0500, Chris R Miller
>> <lordsauronthegreat at gmail.com> said:
>>
>>>> If you had a smart enough dynamic linker and the signature of each
>>>> function in the virtual table, you could do that in D too by creating
>>>> virtual tables and updating offsets in the code accordingly while
>>>> linking. (Objective-C doesn't work like that, but it has the same
>>>> effect.) Alternativly, it could be done in some static initialisation
>>>> phase.
>>>
>>> An increasingly interesting toy to study (I would think) would be
>>> Categories - the ability to take an existing class and just randomly
>>> tack on additional receivers. Perhaps this is exclusive to
>>> Objective-C's message-receiver architecture, but it's a curious little
>>> technology nonetheless.
>>
>> I'm sure we could add something like categories with what I'm proposing
>> above. In fact, many people on this list have requested a way to write
>> extensions to classes: more methods you can invoke using the dot syntax.
>> Perhaps virtual tables built at runtime could allow people to write class
>> extensions and still be able to override extension methods in subclasses.
>>
>
> It would be great if D could have categories/open classes and you could do
> something like this:
>
> class A
> {
> void foo () {}
> }
>
> class A
> {
> void bar () {}
> }
>
> void main ()
> {
> auto a = new A;
> a.foo;
> a.bar;
> }
>
> And it should of course work on classes you don't have access to the
> source code.
That's similar to C#'s partial classes:
// Error
class A
{
void foo () {}
}
class A
{
void bar () {}
}
// Ok
partial class B
{
void foo () {}
}
partial class B
{
void bar () {}
}
More information about the Digitalmars-d
mailing list