Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Daniele Futtorovic Newsgroups: comp.lang.java.programmer Subject: Re: "Program to an interface" - When to break a design pattern Date: Sun, 08 May 2011 16:15:02 +0200 Organization: A noiseless patient Spider Lines: 60 Message-ID: References: <9dt5s6dalhetgfe99qs92c02hf0dbas44e@4ax.com> <2psjssq4zj.fsf@shell.xmission.com> <2poc3gq3p2.fsf@shell.xmission.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 8 May 2011 14:15:02 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="ujjzbENlA81PtoTBdY731Q"; logging-data="7952"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Eg1jprsp+lXcKhiEFTPbX" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 In-Reply-To: Cancel-Lock: sha1:FegcT6I0XoQFkiUkqqP/VW68WZ4= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3813 On 08/05/2011 05:05, Arved Sandstrom allegedly wrote: > 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. Them's fighting words. Show me a code example with a method, that is not a factory method; that returns a LinkedHashMap instance; for which it matters to the caller that the return type be declared as LinkedHashMap, rather than Map. -- DF. An escaped convict once said to me: "Alcatraz is the place to be"