Re: Programming to an Interface
- From: "GoogleEyeJoe" <crgsmrt@xxxxxxxxxxx>
- Date: 13 May 2006 05:38:40 -0700
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
.
- Follow-Ups:
- Re: Programming to an Interface
- From: H. S. Lahman
- Re: Programming to an Interface
- From: Patrick May
- Re: Programming to an Interface
- From: Ed
- Re: Programming to an Interface
- References:
- Programming to an Interface
- From: GoogleEyeJoe
- Re: Programming to an Interface
- From: Patrick May
- Programming to an Interface
- Prev by Date: Re: Searching OO Associations with RDBMS Persistence Models
- Next by Date: Re: Programming to an Interface
- Previous by thread: Re: Programming to an Interface
- Next by thread: Re: Programming to an Interface
- Index(es):
Relevant Pages
|