Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: "Program to an interface" - When to break a design pattern

Reply
Thread Tools

Re: "Program to an interface" - When to break a design pattern

 
 
Roedy Green
Guest
Posts: n/a
 
      05-05-2011
On Thu, 05 May 2011 12:21:55 -0700, Zapanaz
<http://joecosby.com/code/(E-Mail Removed)> wrote, quoted or indirectly
quoted someone who said :

>The problem is, where I'm creating sortedMap above, I need the map to
>retain the insertion order. If what's returned actually is a Map,
>rather than a LinkedHashMap, then the results the user actually sees
>are going to be in the wrong order. Making things worse, in this case,
>nothing would actually break, only the end user would notice anything
>was actually wrong.


The idea of an interface is you should be able to substitute some
other implementation and all should work unmodified. That is not the
case with the interface you chose. You need to either find or create
an interface that nails down all the desired behaviour, or use the
original actual implementation.

I am not a big fan of this pattern for the following reasons:
1. it slows down access.
2. it obfuscates just what the code is using NOW for the
implementation.
3. It is more verbose, giving you one more thing you have to eyeball
carefully and make dance through the genericity hoops. That makes for
buggier code.

The main place it would pay off is if you plan to later do some fine
tuning, and want to leave open the option of easily substituting your
own tuned collection classes.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Politicians complain that Kindles and iBooks are killing jobs by
destroying the paper book industry. I see it that they have create a way
to produce books for less than a third the cost without destroying forests
and emitting greenhouse gases in the process. They have created wealth.
They are encouraging literacy and cutting the costs of education.


 
Reply With Quote
 
 
 
 
Jim Janney
Guest
Posts: n/a
 
      05-06-2011
Roedy Green <(E-Mail Removed)> writes:

> On Thu, 05 May 2011 12:21:55 -0700, Zapanaz
> <http://joecosby.com/code/(E-Mail Removed)> wrote, quoted or indirectly
> quoted someone who said :
>
>>The problem is, where I'm creating sortedMap above, I need the map to
>>retain the insertion order. If what's returned actually is a Map,
>>rather than a LinkedHashMap, then the results the user actually sees
>>are going to be in the wrong order. Making things worse, in this case,
>>nothing would actually break, only the end user would notice anything
>>was actually wrong.

>
> The idea of an interface is you should be able to substitute some
> other implementation and all should work unmodified. That is not the
> case with the interface you chose. You need to either find or create
> an interface that nails down all the desired behaviour, or use the
> original actual implementation.
>
> I am not a big fan of this pattern for the following reasons:
> 1. it slows down access.
> 2. it obfuscates just what the code is using NOW for the
> implementation.
> 3. It is more verbose, giving you one more thing you have to eyeball
> carefully and make dance through the genericity hoops. That makes for
> buggier code.
>
> The main place it would pay off is if you plan to later do some fine
> tuning, and want to leave open the option of easily substituting your
> own tuned collection classes.


Wandering off the original topic, this might interest you if you haven't
already seen it, on the subject of deciding when to break rules:

http://www.miller-mccune.com/culture...-composer-8507

--
Jim Janney
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 1 01-22-2012 10:48 PM
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 0 01-22-2012 10:26 PM
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 0 01-22-2012 10:25 PM
Re: "Program to an interface" - When to break a design pattern Jim Janney Java 43 05-15-2011 04:25 PM
May I have a example of design pattern of "composite", I still feel fuzzy after reading book of Addison-Wesley's"design pattern " jones9413@yahoo.com C++ 1 08-31-2007 04:09 AM



Advertisments