Question on Interface.

dennis luehring dl.soluz at gmx.net
Wed Aug 7 00:19:21 PDT 2013


Am 07.08.2013 09:11, schrieb SteveGuo:
> 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.
>

if D would allow this - what is then the difference between a class with 
your methods as virtuals + your string?

interface are for loosier coupling then classes - thats why only 
declerations not implementations (like your string) are allowed, same 
goes to Java and C# (and i think most other interface having languages)





More information about the Digitalmars-d mailing list