<$BlogRSDUrl$>

Thursday, January 05, 2006

ImplicitInterfaceImplementation 

ImplicitInterfaceImplementation: " ImplicitInterfaceImplementation design 4 January 2006 Both Java and C# share the same model of pure interface types. You declare a pure interface by going interface Mailable, then you can declare you implement it with class Customer implements Mailable (in Java). A class may implement any number of pure interfaces. One of the things this model ignores is that you have implicit interfaces whenever you have a class. The implicit interface Customer is all the public members declared on Customer. One thing that neither Java nor C# allow you to do is to implement an implicit interface - you cannot write class ValuedCustomer implements Customer What would it mean to implement an implicit interface? Essentially it would tell the type system that the ValuedCustomer class implements all the methods declared in the public interface of Customer but does not take any of its implementation, that is its public method bodies, and non public methods or data. In other words we have interface-inheritance but not implementation-inheritance. When would this be useful? One case I remember from the past was in the old days of Java, before the current collections framework. We wanted to replace the Vector class with an implementation of our own, but couldn't because Vector was a class and we could only subclass it. From time to time you run into cases like this wh"

This page is powered by Blogger. Isn't yours?