To interface or not to interface

Walter Bright newshound1 at digitalmars.com
Mon May 24 11:10:26 PDT 2010


Steven Schveighoffer wrote:
> I'd ask the naysayers of interfaces for dcollections, and also the 
> supporters: what is the point of having interfaces in D?  Are interfaces 
> pretty much obsolete, and I am just nostalgic about their utility?

Interfaces are for runtime polymorphism, rather than compile time polymorphism. 
They are especially useful for things like:

1. runtime plugin interfaces
2. designs where strict implementation hiding is desired
3. to have binary libraries (shared and static)
4. to support Java/C# style coding
5. reduced code memory footprint
6. experience shows they are an excellent fit for user interfaces


Compile time polymorphism, such as what templates provide, are most useful for:

1. maximum performance
2. minimal data memory consumption
3. better compile time checking


I believe the tradeoffs for collection types favor compile time polymorphism 
because:

1. performance is often critical for collections
2. C++ STL has shown the success of this approach
3. collections must fit in naturally with ranges, and ranges are compile time 
polymorphic


More information about the Digitalmars-d mailing list