C#'s greatest mistakes

Adam Burton adz21c at gmail.com
Sun Nov 28 07:09:16 PST 2010


Jonathan M Davis wrote:

> On Saturday 27 November 2010 19:40:09 Michel Fortin wrote:
>> On 2010-11-27 20:55:51 -0500, Adam Burton <adz21c at gmail.com> said:
>> > Personally I think having an "implements" makes sense (that loops
>> > through the methods of an interface and checks the type has matching
>> > methods, not the same as having a class "implement" an interface which
>> > is more like inheritance). However as you say, that is not how
>> > interfaces in their current form are designed to be used so I
>> > understand why people disagree.
>> 
>> Well, if you consider the previously discussed 'adaptTo' function
>> template, all types can be adapted to an interface (via a
>> template-generated wrapper class). So "implements" for structs isn't
>> too far off, as you can use the struct to implement the interface via
>> 'adaptTo'.
> 
> Except that
> 
> 1, adaptTo!() is going to wrapping the struct in a class, so it's
> technically the class which implements the interface (even if it's just a
> wrapper).
Exactly
> 
> 2. More importantly, now you have the added confusion of is it a class, a
> struct, or a struct wrapped by a class that you're dealing with? So,
> talking about implements can quickly become confusing.
This is why interfaces fall down when being called "interfaces". They force 
reference semantics onto the type, but someone implementing a struct will 
have done so over a class for a good reason. Hence adaptTo can cause 
confusion.
> 
> It quickly starts looking like we need new terms which are more precise if
> we want to have clear conversations on the matter.
> 
> - Jonathan M Davis
That was basically what I was getting at. For me an interface is a 
collection of methods and properties that a type can implement (actually I 
prefer the conformsTo someone mentioned earlier). Where as in reality D has 
it more like a basic type of class that can be inherited and implment its 
abstract methods + properties.

Constraints with templates actually model the idea of an interface far 
better, they check whether said Type conforms to the interface it expects 
and uses it. It doesn't force it to be class like, just a type with a set of 
certain methods. So you are truley "programming to an interface". D's 
interfaces make much more sense to me when I think of them as a purely 
abstract dataless class type.


More information about the Digitalmars-d mailing list