Interface questions
Theo
Theo at gmail.com
Sun May 21 10:11:18 UTC 2023
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;
}
}
More information about the Digitalmars-d-learn
mailing list