This needs a different approach

Saaa empty at needmail.com
Mon Apr 28 10:22:15 PDT 2008


"Robert Fraser" <fraserofthenight at gmail.com> wrote in message 
news:fv4t21$1ue1$1 at digitalmars.com...
> Saaa wrote:
>> I have this piece of code:
>>
>> enum { APPLE, PEAR .. PLUM}
>>
>> switch (data.type)
>>   {
>>    case APPLE:
>>    groupModule.appleModule.eat();
>>     break;
>>    case PEAR:
>>    groupModule.pearModule.eat();
>>     break;
>> ..
>> ..
>>    case PLUM:
>>    groupModule.plumModule.eat();
>>     break;
>>    default:
>>     break;
>>   }
>>
>> As the function is always the same I'd rather see a lookup iso an 
>> iteration over all options.. but how?
>>
>> groupModule.(data.type).eat();
>>
>> Something like this is both faster and a lot less to code :)
>
> Isn't this what inheritance and polymorphism is all about?

Could you elaborate on that?
The eat functions are totally different btw. 




More information about the Digitalmars-d-learn mailing list