[dmd-beta] D2 2.058 beta

Steve Schveighoffer schveiguy at yahoo.com
Thu Feb 9 07:09:24 PST 2012





----- Original Message -----
> From: Sönke Ludwig <ludwig at informatik.uni-luebeck.de>
>
> Artificial example (I have a different use case, but the pronciple is
> similar):
> 
> interface ILinkedListItem {
>   LinkedListItem next();
>   void next(LinkedListItem v);
> }
> 
> LinkedList objectStore;
> 
> class C : protected ILinkedListItem {
>   this()
>   {
>     objectStore.add(this);
>   }
> 
>   protected LinkedListItem next() {...}
>   protected void next(LinkedListItem v) {...}
> }
> 
> So the intent is that you don't have access to these methods from the
> outside, but that C can still implement the interface to pass it only to
> certain receivers (the objectStore list in this case).

1. using a template for a container like linked list is preferred to using interfaces.
2. you can achieve something similar using inner classes or class literals:

class C
{
   private class LLItem : ILinkedListItem{
      LinkedListItem next() {...}
      void next(LinkedListItem v) {...}
   }

   this()
   {
       objectStore.add(new LLItem);
   }
}

-Steve



More information about the dmd-beta mailing list