Re: Programming to an Interface



On 2006-05-14 02:46:57 -0500, Laurent Bossavit <laurent@xxxxxxxxxxxxxxxxxxxx> said:

I think the point here is that one designs the interface first and then the implementation.

Whoever coined the phrase "Program to an interface" must have meant something else; otherwise they would have said "Program the interface first." From the start of this thread I've been wondering about the significance of phrasing it that way, program *to* an interface.

Any ideas ?

Laurent

I've always taken it to be a restatement of the Dependency Inversion Principle. When you call a method, call it on an interface or an abstract class, not on a concrete class.
--
Robert C. Martin (Uncle Bob)  | email: unclebob@xxxxxxxxxxxxxxxx
Object Mentor Inc.            | blog:  www.butunclebob.com
The Agile Transition Experts  | web:   www.objectmentor.com
800-338-6716                  |



.



Relevant Pages

  • Re: Declaring a Constructor in an Interface?
    ... i have read many places that an interface is faster than ... but would You also claim that an abstract class ... Dennis JD Myrén ... > Virtual methods always means performance overhead. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Java/J2EE Openings in RTP, NC
    ... JSP, EJB, DAO Developer ... An abstract class is declared with the keyword "class" and is an implementation, i.e., its methods can contain bodies. ... An interface is a declaration of public method signatures which taken together represent a type with a defined contract for interaction with other types. ... A "Type 1" JDBC driver is a bridge to an ODBC driver which in turn interacts with the data store. ...
    (comp.lang.java.programmer)
  • Re: Abstract class or interface?
    ... >derived classes can only inherit one abstract class. ... The interface properties/methods have no implementation. ... and rotate "things" along all three X, Y, and Z coordinate axis. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Adding abstract class...
    ... Therefore I think it is often best to keep the interface ... >>still probably best to keep the interface and add the abstract class ... Strictly speaking this is not correct, an abstract base class by definition ... It would be more correct to say there is a negligible performance penalty in ...
    (comp.object)
  • Re: public interface method Id rather not be
    ... > If I use an interface internally for my application, ... > I have a validation method which ordinarilly would be private. ... class can be extended by an inner class, ... method that returns the abstract class type when it creates ...
    (comp.lang.java.programmer)