Sealed classes - would you want them in D? (v2)

KingJoffrey KingJoffrey at KingJoffrey.com
Sat May 19 07:57:39 UTC 2018


On Saturday, 19 May 2018 at 04:01:18 UTC, KingJoffrey wrote:
> So I've come full circle again, and believe my idea is worth 
> further consideration.

how about this (use a proper annotation).

This will be less likely to confuse anyone from other languages.

e.g

-------------------
module test;

@safeinterface class Dog
{
     private string noiseType = "woof";

     public string makeNoise()
     {
         return this.noiseType;
     }
}

void main()
{
     import std.stdio;

     auto dog = new Dog;
     dog.noiseType = "meow"; // no way jose - requires use of the 
safe interface!
     writeln(dog.makeNoise()); // phew! cause dogs can only bark.
}
-------------------


More information about the Digitalmars-d mailing list