Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Jim Janney Newsgroups: comp.lang.java.programmer Subject: Re: "Program to an interface" - When to break a design pattern Date: Thu, 05 May 2011 14:42:49 -0600 Organization: As little as possible Lines: 26 Message-ID: <2poc3gq3p2.fsf@shell.xmission.com> References: <9dt5s6dalhetgfe99qs92c02hf0dbas44e@4ax.com> <2psjssq4zj.fsf@shell.xmission.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx01.eternal-september.org; posting-host="dZdavj/jUDynNQgDq5jkeA"; logging-data="6321"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0jCFPj5bVeo1+caGD/AJX" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:QTpXpVIM0vj82boCSNfq0v/Krt8= sha1:BiWkJD8j/AwdNw8cR2syGaOmejg= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3588 Daniele Futtorovic writes: > On 05/05/2011 22:14, Jim Janney allegedly wrote: >> The point of programming to the interface is to make it easier to >> substitute a different implementation, which implies that any >> reasonable implementation can be used. If this is not true, if the >> code that uses the object relies on behavior only found in one >> implementation, then there is no benefit to using the interface, and >> you make it more inviting for someone to break things later on. So >> in this case, no, programming to the interface would be the wrong >> thing to do. The point of design principles is to make you think >> before you break them :-) > > Entirely disagreed. The code shown did not contain any justification for > breaking the pattern in question, and on the opposite, it contained all > the reasons to think more about encapsulation, which is the true > underlying rationale for coding to interfaces -- not polymorphism per se. The justification is not in the code shown, but in the accompanying remark "I need the map to retain the insertion order." There's no interface in the JRE that promises this, and only one class that provides it, which makes encapsulation, shall we say, difficult. -- Jim Janney