Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!border3.nntp.ams.giganews.com!backlog3.nntp.ams.giganews.com!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: Thu, 04 Sep 2014 09:12:52 -0500 From: "Chris Uppal" Newsgroups: comp.lang.java.programmer References: <53de8cd5$0$299$14726298@news.sunsite.dk> <53dea33b$0$292$14726298@news.sunsite.dk> <53f3c592$0$300$14726298@news.sunsite.dk> Subject: Re: Help with Deck of cards assignment and getting it to deal... Date: Thu, 4 Sep 2014 15:14:18 +0100 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5512 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512 Message-ID: Lines: 38 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-mX5t7lYvAdkY/V6wa3Lj/crUpbG4nDJwTvAa8eFyvpVPe/Or0H5G62jT3D/kqPideWkJmyx2R2rVkeo!xpb8aFZmo9/7181v/U5WAsogfDmD/JdK4MODzedvRuiWKly1Gh/TeNcEP4nwpVGO0D52+aYCsEM= 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: 3245 Xref: csiph.com comp.lang.java.programmer:29907 Brixomatic wrote: > In article , Chris Uppal > (chris.uppal@metagnostic.REMOVE-THIS.org) says... > > > > You think that because Card is Comparable<> then people would mess up > > > the core game logic of comparing hands? > > > > What I'd expect to see is people attempting to use the Comparable<> > > interface regardless of the game rules. And then patching their logic > > with ad-hoc special cases when they realised that the pre-defined > > Comparable<> didn't do exactly what the rules require. > > > > Better not to set traps for the unwary. > > Better not use Comparable at all. Put a Comparator implementation in sme > public final field and use that instead, always. Yes. Or a bunch of 'em for commonly occurring situation (Ace high, Ace low, ...). Though I'd be inclined to skip the predefined interfaces altogether (for cards) since the comparison is more likely to be between /hands/. > While overriding hashCode and equals is often beneficial and correct, I > find that implementing Comparable is often a mistake. > > I've hat it numerous times that I ran into problems because some people > implemented Comparable for some special purpose (like "sorting by > name"), but did not implement equals and hashCode accordingly, because > that would have messed up the rest (like equals was "equality by ID" or > "all fields equal" and that must not be changed). What you end up with > is objects that are equal according to "compareTo", but not equal > according to "equals" and "hashCode". That makes sense. -- chris