This needs a different approach

Saaa empty at needmail.com
Tue Apr 29 09:24:09 PDT 2008


> Here's how I would solve it:
>
> interface IFruit
> {
>     void eat();
> }
I understand the interface, its a bit like a (partial) set of rules a class 
needs to implement

>
> IFruit APPLE;
> IFruit PEAR;
> //...
> IFruit PLUM;
Different instances of the interface.

>
> static this()
I use this on a module level, it gets run before main.
Is it the same here?

> {
>     APPLE = new class() IFruit
>     {
>         void eat()
>         {
>             tasteTheJuicyGoodness();
 : D

>         }
>     }
>
>     // ...
> }
How would you make the array of fruits?
Something I can iterate over. like:
fruits[ APPLE,PLUM,APPLE ... PEAR,PLUM];

>
> You could initialize them in different modules, if you wanted, too.
I want that : D 




More information about the Digitalmars-d-learn mailing list