Re: Programming to an Interface
- From: "Ed" <iamfractal@xxxxxxxxxxx>
- Date: 14 May 2006 10:54:03 -0700
Sasa wrote:
As stated in the GoF:
"Program to an interface, not an implementation.
I think it's pretty clear what it means - of course, it is not clear
when to use it.
True, the GoFfers don't anywhere say anything as precise as, "Here's
when to program to an interface ..." but I'd argue that they do imply
when it should be used: whenever vaiance encapsulation is to be
employed.
Let's take a peek, for example, at Chapter Two alone, the case study,
and count how many times the variance encapsulation theme pops up:
1. Section 2.3, Encapsulating the Formatting Algorithm: We can
isolate the algorithm and make it easily replaceable at the same time
by encapsulating it in an object.
2. Section 2.3 again, Strategy Pattern: Encapsulating an algorithm
in an object is the intent of the Strategy Pattern.
3. Section 2.6, Encapsulating Implementation Dependencies: Neither
alternative is very appealing, but what else can we do? The same thing
we did for formatting and embellishment, namely, encapsulate the
concept that varies.
4. Section 2.7, Encapsulating a Request: Here we have another
example of encapsulating the concept that varies ...
5. Sectoin 2.8, Encapsulating Access and Traversal: Once again a
better solution is to encapsulate the concept that varies ...
6. Section 2.8 again, Iterator Pattern: The Iterator pattern
illustrates once more how encapsulating the concept that varies helps
us gain flexibility and reusability.
7. Section 2.8 yet again, Encapsulating the Analysis: From all
indications, we need to encapsulate the analysis in a separate object,
much like we've done many times before.
In case the notion escapes us, the authors also burried a cute, little
land-mine back in the introduction, in the form of the only table in
the entire book that lists all the book's patterns and compares their
intents. Remember the title of that table, Table 1.2?
Object-orientation concerns reuse, yet the table's not entitled,
"Design aspects that design patterns let you reuse." Object-orientation
concerns complexity management, yet the table's not entitled, "Design
aspects that design patterns let you manage."
The table is entitled, "Design aspects that design patterns let you
vary."
Certainly, if GoF don't intend variance encapsulation to be The
Opportunity to program to an interface, then I've misunderstood their
work.
..ed
--
www.EdmundKirwan.com - Home of The Fractal Class Composition
.
- Follow-Ups:
- Re: Programming to an Interface
- From: Sasa
- Re: Programming to an Interface
- References:
- Programming to an Interface
- From: GoogleEyeJoe
- Re: Programming to an Interface
- From: Patrick May
- Re: Programming to an Interface
- From: GoogleEyeJoe
- Re: Programming to an Interface
- From: H. S. Lahman
- Re: Programming to an Interface
- From: Laurent Bossavit
- Re: Programming to an Interface
- From: Sasa
- Programming to an Interface
- Prev by Date: Re: Question on LSP
- 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
|