On Thursday, 17 May 2018 at 07:30:58 UTC, KingJoffrey wrote:
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!
}

--------------------

no, that uses type inferance.
you have to do
Animal dog = new Dog;

Reply via email to