Question on Interface.

2013-08-07 Thread 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 Powe

Re: Question on Interface.

2013-08-07 Thread dennis luehring
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 succe

Re: Question on Interface.

2013-08-07 Thread evilrat
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 i

Re: Question on Interface.

2013-08-07 Thread SteveGuo
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 i

Re: Question on Interface.

2013-08-07 Thread evilrat
On Wednesday, 7 August 2013 at 07:30:52 UTC, SteveGuo wrote: 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

Re: Question on Interface.

2013-08-07 Thread SteveGuo
what? O_o let me explain, abstract class requires its successors to implement all methods, but may have fields. class successors *always* do something, either their methods has derived behavior or overridden ones. so does interface, if you has class derived from interface then its successors ma

Re: Question on Interface.

2013-08-07 Thread Andre Artus
On Wednesday, 7 August 2013 at 08:18:43 UTC, SteveGuo wrote: what? O_o let me explain, abstract class requires its successors to implement all methods, but may have fields. class successors *always* do something, either their methods has derived behavior or overridden ones. so does interface, i

Re: Question on Interface.

2013-08-07 Thread SteveGuo
As mentioned by evilrat earlier the 'string signature' should probably be made a readonly property, set in the constructor. I don't think D supports defining a constructor signature on interfaces (I could be wrong), so you want to define an invariant as part of the contract. You may also wan

Re: Question on Interface.

2013-08-07 Thread JS
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 i