Question on Interface.

evilrat evilrat666 at gmail.com
Wed Aug 7 00:23:01 PDT 2013


On Wednesday, 7 August 2013 at 07:11:58 UTC, SteveGuo wrote:
> I like the concept of interface, It enforces its successors to 
> implement some necessary methods.
>
> Please take a look at the following example:
>
> device.d
> ---------------------------------
> interface device
> {
> // I want the three methods implemented by its successors
>     void PowerOn();
>     void PowerOff();
>     void Reset();
>
>     string signature; // This is not allowed in D, but every 
> device should has a signature.
> }
>
> Why it doesn't support non-static members?
> Actually in many cases, we need an interface which needs 
> enforce its successors to implement necessary methods, 
> meanwhile it needs has its own non-static members.

in this case you could switch to abstract class, or make 
signature a read-only property
@property string signature();


More information about the Digitalmars-d mailing list