Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!69.16.185.16.MISMATCH!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 06 May 2011 01:28:01 -0500 From: Zapanaz Newsgroups: comp.lang.java.programmer Subject: Re: "Program to an interface" - When to break a design pattern Date: Thu, 05 May 2011 23:28:26 -0700 Message-ID: References: <9dt5s6dalhetgfe99qs92c02hf0dbas44e@4ax.com> X-Newsreader: Forte Agent 6.00/32.1186 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 45 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-941LenX/ot3pKe3eoE13AbcgD3I0r1I03XrYOvBJAHn2Mp2174OcEMbxhsMbHBSAuZkF/nrSzORl7L0!ZxYepVMNWuY0WqJZwhuiq6Gut+mAkcQQhHFhDoR7KjyPj17VbVmjTsT2tJBFAHWJtV9ep04= X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2966 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3640 On Thu, 05 May 2011 16:41:33 -0700, Roedy Green wrote: >On Thu, 05 May 2011 12:21:55 -0700, Zapanaz > 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. Thanks Roedy. Your web page was a lot of help to me when I was learning Java years ago, thanks for that too. -- Zapanaz International Satanic Conspiracy Customer Support Specialist http://joecosby.com/ Isn't round the funny side that never ends? :: Currently listening to For His Namesake, by Amboy Dukes/Ted Nugent, from "Journey to the Center of the Mind"