digitalmars.D.learn - Interface questions
- Theo (51/51) May 21 2023 see comments in the code below. they are my questions.
see comments in the code below. they are my questions. But feel free to ignore the comment about 'private(this)' ;-) interface Ship { safe void setSpeed(int speed); safe int getSpeed(); } class PirateShip : Ship { private int speed = 0; // If only I had 'private(this)' !! // how do I know this method is actually an implementation of an interface method // and not a method specific to this class? public void setSpeed(int speed) { this.speed = speed; } // how do I know this method is actually an implementation of an interface method // and not a method specific to this class? public int getSpeed() { return speed; } } class MerchantShip : Ship { private int speed = 0; // If only I had 'private(this)' !! // how do I know this method is actually an implementation of an interface method // and not a method specific to this class? // AND ... how come I can change a safe interface method into a trusted one? public trusted void setSpeed(int speed) { int *s = void; // Mmmm.. and my interface all had safe methods!! this.speed = speed; } // how do I know this method is actually an implementation of an interface method // and not a method specific to this class? // AND ... how come I can change a safe interface method into a trusted one? public trusted int getSpeed() { int *s = void; // Mmmm.. and my interface all had safe methods!! return speed; } }
May 21 2023