Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.glorb.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe09.iad.POSTED!8ad76e89!not-for-mail From: Arved Sandstrom User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110424 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: "Program to an interface" - When to break a design pattern References: <9dt5s6dalhetgfe99qs92c02hf0dbas44e@4ax.com> <2psjssq4zj.fsf@shell.xmission.com> <2poc3gq3p2.fsf@shell.xmission.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Lines: 50 Message-ID: X-Complaints-To: abuse@newsgroups-download.com NNTP-Posting-Date: Sun, 08 May 2011 03:05:13 UTC Organization: Public Usenet Newsgroup Access Date: Sun, 08 May 2011 00:05:08 -0300 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3778 On 11-05-07 10:28 PM, Daniele Futtorovic wrote: > On 08/05/2011 01:26, Zapanaz allegedly wrote: >> On Fri, 06 May 2011 18:25:31 +0200, Daniele Futtorovic >> wrote: >> >>> On 06/05/2011 08:25, Zapanaz allegedly wrote: >>>> On Thu, 05 May 2011 22:48:21 +0200, Daniele Futtorovic >>>> wrote: >>>> >>>>> But the code that *calls* >>>>> getSortedMap() doesn't have to care about whether or not it's a >>>>> LinkedHashMap >>>> >>>> yes, it does. >>>> >>>> The code that calls getSortedMap() has to know whether the results >>>> will be sorted or not. >>> >>> Not unless the calling code inserts in that Map *and iterates* over it, >>> it doesn't. >>> >>> A LinkedHashMap is not sorted. At least not in the absolute sense. It is >>> sorted relatively to another sorting, viz. it (possibly) replicates the >>> iteration order of another Map. But as I have tried to explain before, >>> knowing that it's a LinkedHashMap *without knowing in what order the >>> insertion took place* doesn't tell you *anything* about the iteration >>> order. >> >> I am using the word "sorted" in an incorrect way, it's true. >> >> This is from a real-world application, the results in the map are >> presented in a UI, and they do in fact have to be in a particular >> order in that UI. They are ordered by an algorithm based on a set of >> user-entered choices, and inserted in that order. So if that order >> isn't preserved in the map, the way the items appear in the UI would >> not be what the user had selected. > > This whole discussion is about the declared type, not the runtime type. Sort of helps if the declared type has some reasonable relationship to the possible runtime types, actually. If the contract of the declared type deviates too much from the contract of the possible runtime types, which is the case here, what's the point? > Anyway, I've had enough of this. > Probably just as well. You can't convince everyone to do something ill-advised. AHS