Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!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: Thu, 05 May 2011 14:21:33 -0500 From: Zapanaz Newsgroups: comp.lang.java.programmer Subject: "Program to an interface" - When to break a design pattern Date: Thu, 05 May 2011 12:21:55 -0700 Message-ID: <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: 70 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-feFun++XH0rLDZdAsuPkfT3J12oDEliTVw1DVTgK15gfTHde5T+/jTh+XWkoj/5KKZxZGbzOBBRMiFB!hX/l3l6E1C3a63PpkLXE72eLuvAdbVgvLX4DVt9uUmHEatXgaIDauloehCxaewz/PaNaMkI= 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: 3222 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3578 I've seen this design pattern before http://witte-consulting.com/documents/design-principles/ and, in general, I see the point of it. But say we've got something like this LinkedHashMap sortedMap = this.getSortedMap(); So you have the method public LinkedHashMap getSortedMap() { //do stuff } (not necessarily public) Now the design principle says, the method signature should instead be public Map getSortedMap() { //do stuff } 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. So in this case, it seems to me, that using LinkedHashMap in the method signature makes sense. The fact that the return retains the insertion order is an integral part of what the method does. If nothing else, it's going to save Fred Developer down the line from looking at the code around this Map sortedMap = this.getSortedMap(); and thinking "wait, how do I know getSortedMap() is going to return a result with the right ordering?", and having to waste time digging into that method. *** Opinions? Angry mob with torches and pitchforks? The Spanish Inquisition? -- Zapanaz International Satanic Conspiracy Customer Support Specialist http://joecosby.com/ Soon, Snata will be arriving in a sleigh drawn by red-nosed lamies with an ass hat full of good buoys and gerbils, so be sure to leave him some milf and cockies or he'll put a lump of coke in your sakes! On Blunder and Dunder, and Jenkem and Blitzkrieg! Micheal Jackson, Bill Paxton, Anthraxen and Bilgepump! On Sushi and Belushi, and Sarducci, and Sangwich! Pudknocker, Gobsmacker, Corkstopper, and Cabbage! HUR HUR HUR! Happy Xlameassedness! - Artemia Salina :: Currently listening to Willow Weep for Me, 1965, by Wes Montgomery, from "Smokin' At The Half Note 1965"