Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Jim Janney Newsgroups: comp.lang.java.programmer Subject: Re: "Program to an interface" - When to break a design pattern Date: Thu, 05 May 2011 22:47:12 -0600 Organization: As little as possible Lines: 38 Message-ID: <2pr58co2pb.fsf@shell.xmission.com> References: <9dt5s6dalhetgfe99qs92c02hf0dbas44e@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="dZdavj/jUDynNQgDq5jkeA"; logging-data="16460"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GzxHolrA6WKQ70N5TEfG3" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:oysLZ9JrdAPVr9nFJylRTs4updE= sha1:Hu2bmzoJ9xKr7epyi4yeFgikCr4= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3638 Roedy Green writes: > 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. 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-society/triumph-of-the-cyborg-composer-8507 -- Jim Janney