www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Interface reference

reply Michael Koehmstedt <mykillk gmail.com> writes:
I just read this in the book "Learn to Tango with D", page 73:

"It is not possible to instantiate interfaces, but you can have references to
class instances through the type of an interface that the class implements."

Could anyone give an example of what this means?
Jul 04 2008
parent reply Kirk McDonald <kirklin.mcdonald gmail.com> writes:
Michael Koehmstedt wrote:
 I just read this in the book "Learn to Tango with D", page 73:
 
 "It is not possible to instantiate interfaces, but you can have references to
class instances through the type of an interface that the class implements."
 
 Could anyone give an example of what this means?
 
 
 

interface I { void foo(); } class C : I { override void foo() {} } void main() { I i = new C; // reference to class instance of interface type i.foo(); } -- Kirk McDonald http://kirkmcdonald.blogspot.com Pyd: Connecting D and Python http://pyd.dsource.org
Jul 04 2008
next sibling parent Michael Koehmstedt <mykillk gmail.com> writes:
Thanks Kirk, a simple example is worth a thousand words!

Kirk McDonald Wrote:

 Michael Koehmstedt wrote:
 I just read this in the book "Learn to Tango with D", page 73:
 
 "It is not possible to instantiate interfaces, but you can have references to
class instances through the type of an interface that the class implements."
 
 Could anyone give an example of what this means?
 
 
 

interface I { void foo(); } class C : I { override void foo() {} } void main() { I i = new C; // reference to class instance of interface type i.foo(); } -- Kirk McDonald http://kirkmcdonald.blogspot.com Pyd: Connecting D and Python http://pyd.dsource.org

Jul 05 2008
prev sibling parent "Manfred_Nowak" <svv1999 hotmail.com> writes:
Kirk McDonald wrote:

 // reference to class instance of interface type

... which can be understood as being different from what Michael cited. -manfred
Jul 05 2008