[NAME] ALL.dao.interface.abstract [TITLE] Abstract Interface [DESCRIPTION] Abstract interface is a type that describes how an object can be used, by specifying wha t methods and overloaded operators the object can support. An object is compatible (match ing) to an interface type, if the object supports all the methods and operators that are specified by the interface. Interface is an abstract type, since no instance can be creat ed from an interface, also all the methods of an interface are abstract without implement ation. Here is a simple interface that contains a size checking method, 1 interface HasSize 2 { 3 routine size()=>int 4 } Now we can define a function that can take a parameter of any object that is compatible t o this interface, 1 routine PrintSize( object: HasSize ) 2 { 3 io.writeln( object.size() ) 4 } Then this function can be called upon types such as string, list or map etc. 1 PrintSize( 'hello world' ) 2 PrintSize( { 1, 2, 3 } ); Interface supports inheritance in the same way as class does, 1 interface Resizable : HasSize 2 { 3 routine resize( size :int ) 4 } Similarly, 1 routine Resize( object: Resizable, size: int ) 2 { 3 io.writeln( 'old size:', object.size() ) 4 io.writeln( 'new size:', size ) 5 object.resize( size ) 6 } 7 8 var ls = {} 9 Resize( ls, 5 ) 10 io.writeln( ls ) Interface also supports operator overloading, however, built-in operators for built-in ty pes cannot be checked against an interface, because they are not implemented as methods. So interfaces are normally more useful with class instances and wrapped C/C++ types. Interfaces with the same set of abstract methods are interchangeable, 1 interface HasSize2 2 { 3 routine size()=>int 4 } 5 routine PrintSize2( object: HasSize2 ) 6 { 7 o :HasSize = object; # assign an object of "HasSize2" to a variable of "HasSize"; 8 io.writeln( object.size() ) 9 } 10 PrintSize2( {} );