IanG writes about Implicit Interfaces, referring to Martin Fowlers post on ImplicitInterfaceImplementation, which has generated some discussion.
With implicit interfaces, the runtime would dynamically generate an interface binding for classes which support all the methods declared within the interface. This is especially useful for enable constraints within generics to support generic algorithms, but is also useful outside generics.
Implicit Interfaces highlights one of the advantages of dynamic languages over static languages, late binding, in which methods of the same name can call on object instances of different classes. However, the benefits of calling a function by name without explicitly implementing an interface is not exclusive to dynamic languages. C++, a static language, already provides this ability through function calls inside template definitions. C++’s implementation doesn’t use latebinding so it executes at maximum speed at the expense of heavier code generation.
I wrote about implicit interfaces multiple times in the past. A developer in the C# team previously mentioned to me that CLR team was investigating support for Patterns—a kind of implicit interface—but I haven’t seen any confirmation. Other languages have embarked on related features:
- Concepts. Concepts are being introduced as a cornerstone feature of the next iteration of C++, C++0x. Concepts introduce type checking, constraints, and better error messages for templates.
- Dynamic Interfaces. VB 9 includes a new feature called dynamic interfaces. The proposed implementation uses latebinding through reflection, but could possibly be updated to work with future runtime support for implicit interfaces.