D versus Objective C Comparison

Daniel Keep daniel.keep.lists at gmail.com
Mon Feb 2 19:45:15 PST 2009



Michel Fortin wrote:
> On 2009-02-02 21:19:52 -0500, Daniel Keep <daniel.keep.lists at gmail.com>
> said:
> 
>>
>>
>> Michel Fortin wrote:
>>> [stuff]
>>
>> Wouldn't this be just as well served with Walter's "universal function
>> syntax"; ie:
>>
>> void backup(File this, string backupPath)
>> {
>>   copy(this.path, backupPath ~ "/" ~ this.name);
>> }
>>
>> File someFile;
>> someFile.backup(backupPath);
> 
> It would work in your example, but not in mine. Note the difference:
> 
>     foreach(child; children)
>         child.backup(backupPath ~ "/" ~ this.name);
> 
> Statically, child is a Node here. If at runtime child is a File, the
> backup function is overriden by the FileBackup extension of File, so
> it'd call the backup function from FileBackup, not NodeBackup. If at
> runtime child is a Directory, it'll call DirectoryBackup's backup
> function. At least, that's what it would do in Objective-C using
> categories. And that's why you don't need the visitor pattern in
> Objective-C.

Aaah, yes.

  -- Daniel



More information about the Digitalmars-d mailing list