Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 26 Feb 2013 03:23:17 -0600 Date: Tue, 26 Feb 2013 09:23:16 +0000 From: lipska the kat <"nospam at neversurrender dot co dot uk"> Organization: Trollbusters 3 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120410 Thunderbird/11.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: BlueJ don't know what i did wrong References: <638ed624-9eba-44eb-bcbf-68466e5bb5f1@googlegroups.com> <42d76fca-d365-4030-ae8c-07a806eab87c@googlegroups.com> <1wtai7dd80h80$.6rbtwoyou3gh.dlg@40tude.net> <5q6dnc3pF_HJzLfMnZ2dnUVZ7s-dnZ2d@bt.com> <77afaabf-ec0f-46d6-b3ea-d8f186dbf7e4@googlegroups.com> <512c2745$0$289$14726298@news.sunsite.dk> In-Reply-To: <512c2745$0$289$14726298@news.sunsite.dk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <3a2dnXBuTbOY4rHMnZ2dnUVZ8iWdnZ2d@bt.com> Lines: 53 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-T4UBEVsJPGVVkEdRPppS/XygNX4jcVF+Ki1m09/voXkKEqCeqE/U9kufsktSlLACvopFmfOalH31pUc!cJUaePDo+/YrZ0zUKN6fq34E4/grIhunRFKjpnMBmG7rwEsBlB0Vte4ZX90grF0AUg98bxKv8Hg= X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com 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: 4037 Xref: csiph.com comp.lang.java.programmer:22523 On 26/02/13 03:08, Arne Vajhøj wrote: > On 2/25/2013 2:54 PM, lipska the kat wrote: >> On 25/02/13 18:52, John B. Matthews wrote: [snip] >> >> Why? why use a Deque instead of a Stack? ... because the documentation >> says so? ... A Stack is an abstraction, it's a very widely understood >> abstraction, everyone who has ever read a book on software knows what a >> stack is. push, pop, peek, they are Stack methods, you don't need >> anything else for a Stack, even peek is questionable. Providing a method >> to add something to the bottom of a Stack doesn't make sense in terms of >> the 'stackness' of a Stack. It just adds meaningless and unneeded >> complexity and confusion, particularly for a beginner to Java. > > You are aware that Stack<> provides elementAt, insertElementAt and > removeElementAt? Y'know what Arne, you are quite predictable, it was a toss up between you and Lew as to who would point that out first ... ding ! we have a winner. Vector provides the methods you mention, not Stack ... and before you go into a long diatribe about inheritance you can save your breath, I'm fully aware of those implications. If you use Vector methods on a Stack then you are intentionally breaking the contract of Stack. This is simply poor coding practice, it makes your code harder to read and maintain and exposes a confused understanding of abstraction. If you want Vector methods use a Vector, if you want a Stack, use a Stack. It constantly amazes me that supposedly experienced developers don't understand this simple, fundamental rule of Object Oriented Software Design. What's the contract of Deque ... a double ended queue? That in itself breaks the (humanly acceptable) contract of Queue. If a Queue is double ended it's not (conceptually) a Queue is it? Stack = LIFO Queue = FIFO Anything else isn't Maybe it would have been better if a Stack had been implemented by Composition WITH Vector rather by extension OF Vector ... But if we have inheritance why not use it eh? (that's a rhetorical question). lipska -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun