Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Joshua Cranmer Newsgroups: comp.lang.java.programmer Subject: Re: "Program to an interface" - When to break a design pattern Date: Thu, 05 May 2011 15:43:08 -0400 Organization: A noiseless patient Spider Lines: 20 Message-ID: References: <9dt5s6dalhetgfe99qs92c02hf0dbas44e@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 5 May 2011 19:43:08 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="LtjcJP1H6uHOtkcPMh0bUA"; logging-data="26984"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Y1Bh2z77dUpKLZA7hIDy0wuoj+fJaano=" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.16pre) Gecko/20110305 Lightning/1.0b3pre Thunderbird/3.1.10pre In-Reply-To: <9dt5s6dalhetgfe99qs92c02hf0dbas44e@4ax.com> Cancel-Lock: sha1:AiqjzK3UlbgXqdGvtZC1vQposgs= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3581 On 05/05/2011 03:21 PM, Zapanaz wrote: > 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. It's still the same map, whether you return it as a Map or as a LinkedHashMap. That is, the same iterator will still be called, and will still return the elements in the same order independent of how it was called. If you're worried that a later developer might not see that it is in the proper order, you can include it in the documentation. Or perhaps return SortedMap instead ;-). -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth