This needs a different approach

Robert Fraser fraserofthenight at gmail.com
Mon Apr 28 20:01:50 PDT 2008


Saaa wrote:
> Could you elaborate on that?
> The eat functions are totally different btw. 

Here's how I would solve it:

interface IFruit
{
     void eat();
}

IFruit APPLE;
IFruit PEAR;
//...
IFruit PLUM;

static this()
{
     APPLE = new class() IFruit
     {
         void eat()
         {
             tasteTheJuicyGoodness();
         }
     }

     // ...
}

You could initialize them in different modules, if you wanted, too.


More information about the Digitalmars-d-learn mailing list