[NAME]
ALL.dao.interface.concrete

[TITLE]
Concrete Interface

[DESCRIPTION]

When a type need to be used in places where an abstract interface type is expected, but 
the type does not support all the methods defined by the abstract interface, a concrete i
nterface can be defined for the (target) type to implement the methods of the abstract in
terface, so that the target type can be used wherever the abstract interface type is expe
cted. For example, 
     
   1  # Abstract interface:
   2  interface SomeInterface
   3  {
   4      routine SomeMethod();
   5  }
   6  
   7  # Concrete interface:
   8  interface SomeInterface for SomeTargetType
   9  {
  10      routine SomeMethod(){
  11      }
  12  }
     
Here the second interface type is a concrete one. It has a generic-like type name: 
interface<SomeInterface<SomeTargetType>>, which stands for the concrete interface type it
self. When a value of the target type SomeTargetType is used in places where the interfac
e type SomeInterface is expected, the value will be automatically casted to the interface
type by wrapping it as an instance of the concrete interface. Such instance also has a ge
neric-like type name: SomeInterface<SomeTargetType>. And it is also automatically casted 
to the target type when needed.

Concrete interfaces also support inheritance: 
     
   1  interface SubInterface : SomeInterface
   2  {
   3      routine SomeMethod2();
   4  }
   5  interface SubInterface for SomeTargetType : SomeInterface<SomeTargetType>
   6  {
   7      routine SomeMethod2(){
   8      }
   9  }
     
The abstract interface SubInterface must have been derived from  SomeInterface. And the t
arget types must be the same.

More example, 
     
   1  interface InterA
   2  {
   3      routine size()=>int
   4      routine serialize()=>string
   5  }
   6  
   7  interface InterB : InterA
   8  {
   9      routine []( index: int ) => float
  10  }
  11  
  12  interface InterA for int
  13  {
  14      routine size(){
  15          io.writeln( "InterA<int>::size()", std.about(self) )
  16          return self + 1;
  17      }
  18      routine serialize() => string { return "abc" + (string) self; }
  19  }
  20  
  21  var a: InterA = 123       # a: value type InterA<int>; variable type InterA;
  22  var b = (InterA) 123;     # b: value type InterA<int>; variable type InterA<int>;
  23  var c: InterA<int> = 123  # c: value type InterA<int>; variable type InterA<int>;
  24  
  25  io.writeln( a.size() )
  26  io.writeln( (int) a )
  27  
  28  var d: int = c
  29  
  30  var e: list<InterA<int>> = { 123 }
  31  
  32  e.append(456)
  33  
  34  var f: list<InterA> = { 678 }
  35  
  36  f.append(456)
  37  
  38  io.writeln( e, f )