------- Comment #10 from  2009-01-20 17:15 -------
But I can still cast to the interface.  Protection attributes are compile-time
entities, they are not flagged at runtime:

SoundManager s;
Object o = s;

INetworkListener inl = cast(INetworkListener)o;

The compiler just looks in the object's list of interfaces to see if it finds
that interface.  There is no protection associated with it at runtime.

What you are asking for requires a major compiler redesign for limited value. 
You can easily implement what you want using a private inner class:

interface INetworkListener {
    void acceptNetworkPacket();

class NetworkManager
    static void registerNetworkListener(INetworkListener listener) { ... }

class SoundManager
    private class NetworkListener : INetworkListener
      void acceptNetworkPacket() {
        // ...

    this() {
        NetworkManager.registerNetworkListener(new NetworkListener);

This is similar to how Java works with anonymous classes.  D can do the same
thing I think, but I can't remember the syntax right now.


Reply via email to