Sealed classes - would you want them in D? (v2)
KingJoffrey
KingJoffrey at KingJoffrey.com
Thu May 17 07:30:58 UTC 2018
On Thursday, 17 May 2018 at 06:03:19 UTC, arturg wrote:
>
> you could declare the public api of your class inside an actual
> interface then use it instead of the class, that wont give you
> access to the private members of the class.
you mean like this?
--------------------
module test;
interface Animal { string makeNoise(); }
class Dog : Animal
{
private string noiseType = "woof";
override string makeNoise()
{
return this.noiseType;
}
}
void main()
{
import std.stdio;
auto dog = new Dog;
dog.noiseType = "meow"; // grr!
writeln(dog.makeNoise()); // wtf! Thanks to D, my dog can now
meow!
}
--------------------
More information about the Digitalmars-d
mailing list