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!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 06 May 2011 09:03:50 -0500 Date: Fri, 06 May 2011 07:03:37 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 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> <2pk4e4q2sq.fsf@shell.xmission.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 23 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 75.8.126.96 X-Trace: sv3-rOZ2cxrUhNWDn+zv5w3YwKhQyQ3I4+PBbhPzGymT8Lh3DbZpEN+B+m5pdf25lceyMpD7kINJAbCoCEv!zvlsLmvGnHBRXu0lRAJDkqG9SW/xvjwvVx+JrfhTIiWZ60Q1SzOeGa9Wb8Hrqog38A87T4YMmbgx!/zS4J2dGYvPXagRhDIl/VrRRZOQS8zjIqF/5KfmCGWc= 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: 2281 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3685 On 5/6/2011 3:24 AM, Arved Sandstrom wrote: ... > As far as your nuance is concerned, I'm interested (the _OP_ is > interested) in providing a map with predictable insertion order. Map > does not satisfy that; LinkedHashMap does. If I return Map then I am > making a mistake. ... I think this is the key point. Compare the following two rules: 1. Program to an interface. 2. Program to the least specific type that meets the requirements, with preference for interfaces. Much of the time, the two rules give the same result. They differ in cases like this one, where there is no interface that meets the requirements. The second rule also helps with deciding which interface to use. If you only need a Set, don't specify a SortedSet. Patricia