Re: Programming to an Interface



Hi Patrick,

Thank you for the reply.

- Defining the interface encourages you to think in terms of the
behavior you need to provide rather than how to implement it.

Isn't this inherent in the design of the classes anyway? I mean, you
don't create methods on class without first thinking of the reason
behind having the functionality. Isn't this one of the things to do
when outlining what the class is for, i.e. what should its inputs and
outputs be...

- The implementation of the behaviors exposed by the interface
can be changed without impacting users of the interface. The
implementation selection can even be deferred until runtime.

Is this not the same for methods of an object? Isn't this one of the
advantages of encapsulation. An object's method can be changed
internally (in its functionality) without having a direct impact on the
client of the object. How does implementing an interface differ from a
non-interface method of an object in this respect?

- Users of the interface are less likely to become coupled to implementation-specific details.

Would this not be the case only if the class was designed badly in the
first instance? Surely, as a designer of a class you would only expose
those parts of the class that you would want the client to use, in the
same way as you would define interface members that you would want
clients to use...?

Many thanks for your help. However, I am still don't think I've yet
found a reason why from programming to interfaces is better than
programming to implementation, with the exception of polymorphic
behaivour. It appears to me that programming to interfaces suffer from
the same downfalls as programming to an object's exposed methods...

Regards,

Craig.


You are, of course, correct that changing

.



Relevant Pages

  • Re: Too early implementation
    ... framework to try it. ... write code heavily focused on user interface. ... game programming as in other domains), and in those cases I generally ... really wrong with the design. ...
    (comp.lang.python)
  • SENIOR A.I. SOFTWARE ENGINEER POSITION - $90-120K - Dallas
    ... I have an Artificial Intelligence Software Engineer position utilizing ... C++, Prolog & LISP with a client in Plano, Tx. ... May design and build prototype applications. ... Expert C and C++ programming experience. ...
    (comp.lang.prolog)
  • SENIOR A.I. SOFTWARE ENGINEER POSITION - $90-120K - Dallas
    ... I have an Artificial Intelligence Software Engineer position utilizing ... C++, Prolog & LISP with a client in Plano, Tx. ... May design and build prototype applications. ... Expert C and C++ programming experience. ...
    (comp.lang.lisp)
  • Re: Programming to an Interface
    ... I think the problem you are having with it is related to the point Daniel T. made that you are thinking about it at too low a level of abstraction (i.e., the mechanics of the OOPL de jour rather than as a design issue). ... I think the point here is that one designs the interface first and then the implementation. ... I believe the point here is that interfaces allow one to define responsibilities in terms of invariants, often at a higher level of abstraction than particular implementations. ... One has identical implementation behaviors for both classes but the interface that the client sees is much more generic in the second case. ...
    (comp.object)
  • Re: APL in its ghetto (?)
    ... Dyalog APL has just about everything you mentioned, ... powerless user interface, and no one on this thread advocats that. ... It's nonsense that the design of serious applications should NOT be ... "neither is user interface design a kind of "programming" in any ...
    (comp.lang.apl)