Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #20377 > unrolled thread
| Started by | infinitum3d@hotmail.com |
|---|---|
| First post | 2012-12-16 07:38 -0800 |
| Last post | 2012-12-18 10:35 -0800 |
| Articles | 20 on this page of 100 — 15 participants |
Back to article view | Back to comp.lang.java.programmer
proper use of .java files (layout) infinitum3d@hotmail.com - 2012-12-16 07:38 -0800
Re: proper use of .java files (layout) Robert Klemme <shortcutter@googlemail.com> - 2012-12-16 16:43 +0100
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-16 10:50 -0500
Re: proper use of .java files (layout) "John B. Matthews" <nospam@nospam.invalid> - 2012-12-16 16:25 -0500
Re: proper use of .java files (layout) markspace <-@.> - 2012-12-16 08:24 -0800
Re: proper use of .java files (layout) Lew <lewbloch@gmail.com> - 2012-12-17 10:28 -0800
Re: proper use of .java files (layout) markspace <-@.> - 2012-12-17 13:17 -0800
Re: proper use of .java files (layout) Lew <lewbloch@gmail.com> - 2012-12-17 13:51 -0800
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-17 20:55 -0500
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-17 18:18 -0800
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-17 21:28 -0500
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-17 21:10 -0800
Re: proper use of .java files (layout) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-18 08:53 -0500
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-18 09:13 -0800
Re: proper use of .java files (layout) Patricia Shanahan <pats@acm.org> - 2012-12-18 09:23 -0800
Re: proper use of .java files (layout) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-18 13:49 -0500
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-18 15:05 -0800
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-18 20:11 -0500
Re: proper use of .java files (layout) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-18 21:07 -0500
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-19 09:33 +0000
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-19 10:12 -0800
Re: proper use of .java files (layout) Lew <lewbloch@gmail.com> - 2012-12-19 13:35 -0800
Re: proper use of .java files (layout) Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-12-19 15:55 -0600
Re: proper use of .java files (layout) Lew <lewbloch@gmail.com> - 2012-12-19 14:01 -0800
Re: proper use of .java files (layout) Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-12-19 16:05 -0600
Re: proper use of .java files (layout) Patricia Shanahan <pats@acm.org> - 2012-12-19 04:06 -0800
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-19 12:24 +0000
Re: proper use of .java files (layout) Lew <lewbloch@gmail.com> - 2012-12-19 13:36 -0800
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-18 20:10 -0500
Re: proper use of .java files (layout) Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-12-18 12:14 -0600
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-18 20:04 -0500
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-19 10:14 -0800
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-19 19:18 -0500
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-20 11:05 +0000
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-27 21:43 -0500
Re: proper use of .java files (layout) Lew <lewbloch@gmail.com> - 2012-12-27 18:49 -0800
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-27 22:10 -0500
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-20 09:01 -0800
Re: proper use of .java files (layout) Patricia Shanahan <pats@acm.org> - 2012-12-20 09:30 -0800
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-20 13:35 -0800
Re: proper use of .java files (layout) Patricia Shanahan <pats@acm.org> - 2012-12-20 14:00 -0800
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-21 08:58 +0000
Re: proper use of .java files (layout) Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-21 10:36 -0800
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-21 18:43 +0000
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-27 22:05 -0500
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-28 09:57 +0000
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-27 21:59 -0500
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-27 21:53 -0500
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-27 21:54 -0500
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-27 21:48 -0500
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-27 21:11 -0800
Re: proper use of .java files (layout) "John B. Matthews" <nospam@nospam.invalid> - 2012-12-28 06:50 -0500
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-28 13:46 +0000
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-28 09:10 -0800
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-18 09:50 +0000
Re: proper use of .java files (layout) "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2012-12-18 13:09 +0000
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-18 14:05 +0000
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-25 15:06 -0800
Re: proper use of .java files (layout) Patricia Shanahan <pats@acm.org> - 2012-12-26 06:31 -0800
Re: proper use of .java files (layout) Lew <lewbloch@gmail.com> - 2012-12-26 13:21 -0800
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-26 23:38 -0500
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-27 08:37 +0000
Re: proper use of .java files (layout) Robert Klemme <shortcutter@googlemail.com> - 2012-12-27 11:51 +0100
Re: proper use of .java files (layout) Patricia Shanahan <pats@acm.org> - 2012-12-27 08:46 -0800
Re: proper use of .java files (layout) Robert Klemme <shortcutter@googlemail.com> - 2012-12-27 18:20 +0100
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-27 20:48 -0500
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-17 20:58 -0500
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-17 18:22 -0800
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-17 21:39 -0500
Re: proper use of .java files (layout) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-17 21:25 -0500
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-17 21:29 -0500
Re: proper use of .java files (layout) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-17 21:32 -0500
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-17 21:37 -0500
Re: proper use of .java files (layout) Wayne <nospam@all.invalid> - 2012-12-18 18:45 -0500
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-18 20:13 -0500
Re: proper use of .java files (layout) infinitum3d@hotmail.com - 2012-12-16 09:23 -0800
Re: proper use of .java files (layout) infinitum3d@hotmail.com - 2012-12-16 21:07 -0800
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-17 10:32 +0000
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-17 21:03 -0500
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-18 09:34 +0000
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-18 20:00 -0500
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-18 20:01 -0500
Re: proper use of .java files (layout) infinitum3d@hotmail.com - 2012-12-18 06:32 -0800
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-18 15:05 +0000
Re: proper use of .java files (layout) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-18 11:07 -0500
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-18 16:27 +0000
Re: proper use of .java files (layout) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-18 11:44 -0500
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-18 17:21 +0000
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-18 09:21 -0800
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-18 17:39 +0000
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-18 10:40 -0800
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-18 19:05 +0000
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-18 15:15 -0800
Re: proper use of .java files (layout) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-18 14:12 -0500
Re: proper use of .java files (layout) lipska the kat <lipskathekat@yahoo.co.uk> - 2012-12-18 19:39 +0000
Re: proper use of .java files (layout) Gene Wirchenko <genew@telus.net> - 2012-12-18 15:17 -0800
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-18 20:07 -0500
Re: proper use of .java files (layout) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-18 21:11 -0500
Re: proper use of .java files (layout) Arne Vajhøj <arne@vajhoej.dk> - 2012-12-18 22:24 -0500
Re: proper use of .java files (layout) markspace <-@.> - 2012-12-18 10:35 -0800
Page 1 of 5 [1] 2 3 4 5 Next page →
| From | infinitum3d@hotmail.com |
|---|---|
| Date | 2012-12-16 07:38 -0800 |
| Subject | proper use of .java files (layout) |
| Message-ID | <e32ed4f5-58a8-4b3b-9868-d856db8141a8@googlegroups.com> |
I'm trying to figure out the best way to layout a java program. Should I put each object into its own .java file? If I'm making a card game, that would be 52 .java files. Is that crazy? Normal? Or should I separate them by suit and just have 4 .java files? Or by value so there are 13 .java files? Thanks! I3D
[toc] | [next] | [standalone]
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Date | 2012-12-16 16:43 +0100 |
| Message-ID | <aj68hoFsfooU1@mid.individual.net> |
| In reply to | #20377 |
On 16.12.2012 16:38, infinitum3d@hotmail.com wrote: > I'm trying to figure out the best way to layout a java program. > Should I put each object into its own .java file? If I'm making a > card game, that would be 52 .java files. Is that crazy? Normal? Crazy. > Or should I separate them by suit and just have 4 .java files? Or by > value so there are 13 .java files? You better had just one class for Card which has different properties. Which properties you need depends of course on the card at hand and on the application. Sometimes it may make sense to make Card an interface and have different implementing classes. But that all depends on the application that is being written. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2012-12-16 10:50 -0500 |
| Message-ID | <50cdede4$0$291$14726298@news.sunsite.dk> |
| In reply to | #20377 |
On 12/16/2012 10:38 AM, infinitum3d@hotmail.com wrote: > I'm trying to figure out the best way to layout a java program. > Should I put each object into its own .java file? If I'm making a > card game, that would be 52 .java files. Is that crazy? Normal? > > Or should I separate them by suit and just have 4 .java files? Or by > value so there are 13 .java files? You need to distinguish between classes and objects. You will have one class per Java file (actually you can have more than one, but let us keep this simple to start with). When the program runs then you can create one or more instances of that class - those instances are objects. A deck of card will usually be considered 52 instances/objects of 1 class. Arne
[toc] | [prev] | [next] | [standalone]
| From | "John B. Matthews" <nospam@nospam.invalid> |
|---|---|
| Date | 2012-12-16 16:25 -0500 |
| Message-ID | <nospam-BD45D9.16250816122012@news.aioe.org> |
| In reply to | #20380 |
In article <50cdede4$0$291$14726298@news.sunsite.dk>, Arne Vajhøj <arne@vajhoej.dk> wrote: > On 12/16/2012 10:38 AM, infinitum3d@hotmail.com wrote: > > I'm trying to figure out the best way to layout a java program. > > Should I put each object into its own .java file? If I'm making a > > card game, that would be 52 .java files. Is that crazy? Normal? > > > > Or should I separate them by suit and just have 4 .java files? Or > > by value so there are 13 .java files? > > You need to distinguish between classes and objects. > > You will have one class per Java file (actually you can have more > than one, but let us keep this simple to start with). > > When the program runs then you can create one or more instances of > that class - those instances are objects. > > A deck of card will usually be considered 52 instances/objects of 1 > class. infinitum3d: There's a nice example that illustrates this using typesafe enums, introduced in Java 1.5: <http://docs.oracle.com/javase/1.5.0/docs/guide/language/enums.html> -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-12-16 08:24 -0800 |
| Message-ID | <kaksjp$8u7$1@dont-email.me> |
| In reply to | #20377 |
On 12/16/2012 7:38 AM, infinitum3d@hotmail.com wrote:
> I'm trying to figure out the best way to layout a java program.
> Should I put each object into its own .java file? If I'm making a
> card game, that would be 52 .java files. Is that crazy? Normal?
What Arne and Robert said. In this case you want a single class with
two fields, one for suit and one for face value. (You could encode both
the suit and the value in to a single field. However this sort of space
saving is usually counter-productive, unless you're absolutely sure it's
needed.)
public class PlayingCard {
private final int value; // Ace = 1
private final Suit suit;
public static enum Suit { HEARTS, CLUBS, SPADES, DIAMONDS }
... ect....
}
You will of course have to make 52 instances of that class. Do that at
runtime, don't try to make 52 files.
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2012-12-17 10:28 -0800 |
| Message-ID | <20fa5c05-6fcc-47ed-9e80-a44975887928@googlegroups.com> |
| In reply to | #20381 |
markspace wrote:
> public class PlayingCard {
>
> private final int value; // Ace = 1
I would make this an enum.
"Ace = 1" is not a valid association in the problem domain, and its use
as a representation creates risk of an artificial equivalency.
> private final Suit suit;
That's more like it.
> public static enum Suit { HEARTS, CLUBS, SPADES, DIAMONDS }
> ... ect.... [sic]
> }
>
> You will of course have to make 52 instances of that class. Do that at
No "of course" about it.
http://www.hoylegaming.com/rules/showrule.aspx?RuleID=209
> runtime, don't try to make 52 files.
How many cards in a blackjack shoe?
http://en.wikipedia.org/wiki/Blackjack
If you hard-code certain assumptions, e.g., that there are 52 cards in the deck,
your program will be unable to model many games.
--
Lew
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-12-17 13:17 -0800 |
| Message-ID | <kao263$pll$1@dont-email.me> |
| In reply to | #20397 |
On 12/17/2012 10:28 AM, Lew wrote:
> markspace wrote:
>> public class PlayingCard {
>>
>> private final int value; // Ace = 1
>
> I would make this an enum.
>
> "Ace = 1" is not a valid association in the problem domain, and its use
> as a representation creates risk of an artificial equivalency.
I was actually thinking about that. I don't like the idea of trying to
encode most of the values of a face card as enums. Something like this
might be a reasonable compromise.
public static enum Cards {ACE, DEUCE, KING, QUEEN, JACK }
public void set( Cards card, Suit suit ) {
switch( card ) {
case ACE: value = 1; break;
case DEUCE: value = 2; break;
case KING: value = 13; break;
case QUEEN: value = 12; break;
case JACK: value = 11; break;
}
this.suit = suit;
}
public void set( int card, Suit suit ) {
value = card;
this.suit = suit;
}
I also think it might be valuable to have one implementation of
PlayingCard with one internal encoding, then assigning different
semantics (e.g., ace high or low) in a separate game object. Trying to
overload PlayingCard too much with too much business logic seems to
violate encapsulation. A simple wrapper class could easily switch the
value of an ace; so could a custom comparator. Without more
requirements from the OP, it's really hard to guess what of the many
possible solutions is best.
So I went with a simple implementation of "ace" (ace = 1) and I'm
leaving to other logic to decide how to treat that. You could have
other more complicated implementations of PlayingCard, but too much gets
too baroque quickly, imo, especially if you don't need all that
functionality for most use cases.
Another example: in many standard decks, the names of the suits are not
Spades, Hearts, etc. but vary by country. Again I'm leaving that for
some other part of the program. Localization of card names can be done
by wrapping this PlayingCard with a GermanPlayingCard, for example.
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2012-12-17 13:51 -0800 |
| Message-ID | <45eb8d50-e812-4d2e-b53b-b0d4da97d982@googlegroups.com> |
| In reply to | #20398 |
markspace wrote:
> Lew wrote:
>> markspace wrote:
>>> public class PlayingCard {
>>> private final int value; // Ace = 1
>
>> I would make this an enum.
>>
>
>> "Ace = 1" is not a valid association in the problem domain, and its use
>> as a representation creates risk of an artificial equivalency.
> I was actually thinking about that. I don't like the idea of trying to
> encode most of the values of a face card as enums. Something like this
> might be a reasonable compromise.
I wouldn't code *any* of the values of the face cards or the pip cards as anything
in the PlayingCard type.
> public static enum Cards {ACE, DEUCE, KING, QUEEN, JACK
, TEN, NINE, EIGHT, SEVEN, SIX, FIVE, FOUR, TREY, JOKER,
> }
And I'd put them in order {JOKER, ACE, DEUCE, ..., }
> public void set( Cards card, Suit suit ) {
'Card', not 'Cards'.
> switch( card ) {
>
> case ACE: value = 1; break;
That's clumsy. But how will this work for Blackjack?
> case DEUCE: value = 2; break;
> case KING: value = 13; break;
> case QUEEN: value = 12; break;
> case JACK: value = 11; break;
> }
> this.suit = suit;
> }
>
> public void set( int card, Suit suit ) {
> value = card;
Should not be an 'int', I reiterate.
There is nothing "integery" about the card name.
> this.suit = suit;
> }
>
> I also think it might be valuable to have one implementation of
> PlayingCard with one internal encoding, then assigning different
Yes, the "internal encoding" is the enum constant.
> semantics (e.g., ace high or low) in a separate game object. Trying to
That.
> overload PlayingCard too much with too much business logic seems to
Agreed.
> violate encapsulation. A simple wrapper class could easily switch the
Not "switch", assign, and not a "simple wrapper class" but a games rule engine.
> value of an ace; so could a custom comparator. Without more
> requirements from the OP, it's really hard to guess what of the many
> possible solutions is best.
I was going for modeling a playing card so it would work in any card game.
> So I went with a simple
but feckless
> implementation of "ace" (ace = 1) and I'm
> leaving to other logic to decide how to treat that. You could have
> other more complicated implementations of PlayingCard, but too much gets
You've already included too much by having an 'int' value.
> too baroque quickly
^H^H^H^H^H^H^Halready
> , imo, especially if you don't need all that
> functionality for most use cases.
You don't need the 'int' value for any use cases.
> Another example: in many standard decks, the names of the suits are not
> Spades, Hearts, etc. but vary by country. Again I'm leaving that for
Silliness. We know from the OP's problem statement that they intend the French suits.
> some other part of the program. Localization of card names can be done
> by wrapping this PlayingCard with a GermanPlayingCard, for example.
Wrap, wrap, wrap. You sure are addicted to wrapping. I wouldn't recommend that.
How would a 'GermanPlayingCard' delegate to the standard French model?
I'd use a different type that implements a suitable interface, or just use a different enum.
But I can't really see the refactoring clearly from here. I'd need a candidate implementation
to refactor.
--
Lew
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2012-12-17 20:55 -0500 |
| Message-ID | <50cfcd0b$0$293$14726298@news.sunsite.dk> |
| In reply to | #20398 |
On 12/17/2012 4:17 PM, markspace wrote:
> On 12/17/2012 10:28 AM, Lew wrote:
>> markspace wrote:
>>> public class PlayingCard {
>>>
>>> private final int value; // Ace = 1
>>
>> I would make this an enum.
>>
>> "Ace = 1" is not a valid association in the problem domain, and its use
>> as a representation creates risk of an artificial equivalency.
>
> I was actually thinking about that. I don't like the idea of trying to
> encode most of the values of a face card as enums.
Why not?
13 distinct values with an order but no numeric values
seems a perfect fit for enum to me.
> Another example: in many standard decks, the names of the suits are not
> Spades, Hearts, etc. but vary by country. Again I'm leaving that for
> some other part of the program. Localization of card names can be done
> by wrapping this PlayingCard with a GermanPlayingCard, for example.
Or by using standard I18N techniques in the UI layer!
Arne
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@telus.net> |
|---|---|
| Date | 2012-12-17 18:18 -0800 |
| Message-ID | <rgkvc89ffi9l8mnr1la1ev75okigl14nt3@4ax.com> |
| In reply to | #20409 |
On Mon, 17 Dec 2012 20:55:21 -0500, Arne Vajhøj <arne@vajhoej.dk>
wrote:
[snip]
>13 distinct values with an order but no numeric values
>seems a perfect fit for enum to me.
An enum does not guarantee an order.
Do you play poker? Aces are usually high, but can be low in the
case of straights.
[snip]
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2012-12-17 21:28 -0500 |
| Message-ID | <50cfd4b9$0$295$14726298@news.sunsite.dk> |
| In reply to | #20413 |
On 12/17/2012 9:18 PM, Gene Wirchenko wrote: > On Mon, 17 Dec 2012 20:55:21 -0500, Arne Vajhøj <arne@vajhoej.dk> > wrote: > > [snip] > >> 13 distinct values with an order but no numeric values >> seems a perfect fit for enum to me. > > An enum does not guarantee an order. In the Java I use enums have a compareTo method. Arne
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@telus.net> |
|---|---|
| Date | 2012-12-17 21:10 -0800 |
| Message-ID | <oguvc8hejq2dadnmim92vmpqh2ikccv2te@4ax.com> |
| In reply to | #20416 |
On Mon, 17 Dec 2012 21:28:07 -0500, Arne Vajhøj <arne@vajhoej.dk>
wrote:
>On 12/17/2012 9:18 PM, Gene Wirchenko wrote:
>> On Mon, 17 Dec 2012 20:55:21 -0500, Arne Vajhøj <arne@vajhoej.dk>
>> wrote:
>>
>> [snip]
>>
>>> 13 distinct values with an order but no numeric values
>>> seems a perfect fit for enum to me.
>>
>> An enum does not guarantee an order.
>
>In the Java I use enums have a compareTo method.
And how would you handle the aces?
A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
five-high straight).
Human systems can be remarkably exceptional if I may use the word
in the sense of "having an exception".
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2012-12-18 08:53 -0500 |
| Message-ID | <kapshs$ggf$1@dont-email.me> |
| In reply to | #20429 |
On 12/18/2012 12:10 AM, Gene Wirchenko wrote:
> On Mon, 17 Dec 2012 21:28:07 -0500, Arne Vajhøj <arne@vajhoej.dk>
> wrote:
>
>> On 12/17/2012 9:18 PM, Gene Wirchenko wrote:
>>> On Mon, 17 Dec 2012 20:55:21 -0500, Arne Vajhøj <arne@vajhoej.dk>
>>> wrote:
>>>
>>> [snip]
>>>
>>>> 13 distinct values with an order but no numeric values
>>>> seems a perfect fit for enum to me.
>>>
>>> An enum does not guarantee an order.
>>
>> In the Java I use enums have a compareTo method.
>
> And how would you handle the aces?
>
> A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
> five-high straight).
In some "high-low" games, A-5-4-3-2 can be both a
five-high straight *and* an Ace with four low cards,
possibly winning both the "high" and "low" shares of
the pot.
--
Eric Sosman
esosman@comcast-dot-net.invalid
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@telus.net> |
|---|---|
| Date | 2012-12-18 09:13 -0800 |
| Message-ID | <qu81d8tvekubbb4kei79s37r01uc0b3src@4ax.com> |
| In reply to | #20443 |
On Tue, 18 Dec 2012 08:53:58 -0500, Eric Sosman
<esosman@comcast-dot-net.invalid> wrote:
>On 12/18/2012 12:10 AM, Gene Wirchenko wrote:
[snip]
>> And how would you handle the aces?
>>
>> A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
>> five-high straight).
>
> In some "high-low" games, A-5-4-3-2 can be both a
>five-high straight *and* an Ace with four low cards,
>possibly winning both the "high" and "low" shares of
>the pot.
Right. I have rarely ever played high-low and forgot about them.
Does anyone else have an exception to ambush us with? <g>
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2012-12-18 09:23 -0800 |
| Message-ID | <D6GdnT5PxsU1O03NnZ2dnUVZ_rOdnZ2d@earthlink.com> |
| In reply to | #20453 |
On 12/18/2012 9:13 AM, Gene Wirchenko wrote: > On Tue, 18 Dec 2012 08:53:58 -0500, Eric Sosman > <esosman@comcast-dot-net.invalid> wrote: > >> On 12/18/2012 12:10 AM, Gene Wirchenko wrote: > > [snip] > >>> And how would you handle the aces? >>> >>> A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a >>> five-high straight). >> >> In some "high-low" games, A-5-4-3-2 can be both a >> five-high straight *and* an Ace with four low cards, >> possibly winning both the "high" and "low" shares of >> the pot. > > Right. I have rarely ever played high-low and forgot about them. > Does anyone else have an exception to ambush us with? <g> I think that sort of issue could be handled by having game-dependent Comparator<Card,Card> implementations, rather than making Card Comparable. I would be more concerned about jokers, which do not follow the (suit,value) pattern. Patricia
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2012-12-18 13:49 -0500 |
| Message-ID | <kaqdri$316$1@dont-email.me> |
| In reply to | #20456 |
On 12/18/2012 12:23 PM, Patricia Shanahan wrote:
> On 12/18/2012 9:13 AM, Gene Wirchenko wrote:
>> On Tue, 18 Dec 2012 08:53:58 -0500, Eric Sosman
>> <esosman@comcast-dot-net.invalid> wrote:
>>
>>> On 12/18/2012 12:10 AM, Gene Wirchenko wrote:
>>
>> [snip]
>>
>>>> And how would you handle the aces?
>>>>
>>>> A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
>>>> five-high straight).
>>>
>>> In some "high-low" games, A-5-4-3-2 can be both a
>>> five-high straight *and* an Ace with four low cards,
>>> possibly winning both the "high" and "low" shares of
>>> the pot.
>>
>> Right. I have rarely ever played high-low and forgot about them.
>> Does anyone else have an exception to ambush us with? <g>
>
> I think that sort of issue could be handled by having game-dependent
> Comparator<Card,Card> implementations, rather than making Card Comparable.
A comparator might have a hard time declaring "Ace is lower
than Deuce" and "Ace is higher than Deuce" simultaneously ...
And then, there are games where two identical ranks in the
same hand can have different values. With A-A-9, for example, a
Blackjack player would get the desired total of 21 by counting
one Ace as a 1 and the other as an 11. (This appears to be the
class of game the O.P. is interested in.)
> I would be more concerned about jokers, which do not follow the
> (suit,value) pattern.
Other pattern-busters might be the Jacks of Spades and Hearts.
When "one-eyed Jacks are wild," they can be of any rank or suit.
(I've read that the King of Diamonds is sometimes considered wild,
but have never actually encountered the practice.)
--
Eric Sosman
esosman@comcast-dot-net.invalid
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@telus.net> |
|---|---|
| Date | 2012-12-18 15:05 -0800 |
| Message-ID | <5jt1d8p9rudk2amrldqmc3dpm5uhrg2lg7@4ax.com> |
| In reply to | #20463 |
On Tue, 18 Dec 2012 13:49:16 -0500, Eric Sosman
<esosman@comcast-dot-net.invalid> wrote:
[snip]
> Other pattern-busters might be the Jacks of Spades and Hearts.
>When "one-eyed Jacks are wild," they can be of any rank or suit.
>(I've read that the King of Diamonds is sometimes considered wild,
>but have never actually encountered the practice.)
I used to play "Hooks, Crooks, One-Eyed Jacks, and the Man with
the Axe". Hooks are 2's; crooks are 7's. The man with the axe is the
king of diamonds.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2012-12-18 20:11 -0500 |
| Message-ID | <50d1144b$0$290$14726298@news.sunsite.dk> |
| In reply to | #20463 |
On 12/18/2012 1:49 PM, Eric Sosman wrote: > On 12/18/2012 12:23 PM, Patricia Shanahan wrote: >> On 12/18/2012 9:13 AM, Gene Wirchenko wrote: >>> On Tue, 18 Dec 2012 08:53:58 -0500, Eric Sosman >>> <esosman@comcast-dot-net.invalid> wrote: >>> >>>> On 12/18/2012 12:10 AM, Gene Wirchenko wrote: >>> >>> [snip] >>> >>>>> And how would you handle the aces? >>>>> >>>>> A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a >>>>> five-high straight). >>>> >>>> In some "high-low" games, A-5-4-3-2 can be both a >>>> five-high straight *and* an Ace with four low cards, >>>> possibly winning both the "high" and "low" shares of >>>> the pot. >>> >>> Right. I have rarely ever played high-low and forgot about them. >>> Does anyone else have an exception to ambush us with? <g> >> >> I think that sort of issue could be handled by having game-dependent >> Comparator<Card,Card> implementations, rather than making Card >> Comparable. > > A comparator might have a hard time declaring "Ace is lower > than Deuce" and "Ace is higher than Deuce" simultaneously ... > > And then, there are games where two identical ranks in the > same hand can have different values. With A-A-9, for example, a > Blackjack player would get the desired total of 21 by counting > one Ace as a 1 and the other as an 11. (This appears to be the > class of game the O.P. is interested in.) If the logic can be described precisely, then it can be implemented in code. I somewhat suspect that stuff like this will not result in pretty code. Arne
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2012-12-18 21:07 -0500 |
| Message-ID | <kar7gu$4kt$1@dont-email.me> |
| In reply to | #20494 |
On 12/18/2012 8:11 PM, Arne Vajhøj wrote:
> On 12/18/2012 1:49 PM, Eric Sosman wrote:
>> On 12/18/2012 12:23 PM, Patricia Shanahan wrote:
>>> On 12/18/2012 9:13 AM, Gene Wirchenko wrote:
>>>> On Tue, 18 Dec 2012 08:53:58 -0500, Eric Sosman
>>>> <esosman@comcast-dot-net.invalid> wrote:
>>>>
>>>>> On 12/18/2012 12:10 AM, Gene Wirchenko wrote:
>>>>
>>>> [snip]
>>>>
>>>>>> And how would you handle the aces?
>>>>>>
>>>>>> A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
>>>>>> five-high straight).
>>>>>
>>>>> In some "high-low" games, A-5-4-3-2 can be both a
>>>>> five-high straight *and* an Ace with four low cards,
>>>>> possibly winning both the "high" and "low" shares of
>>>>> the pot.
>>>>
>>>> Right. I have rarely ever played high-low and forgot about them.
>>>> Does anyone else have an exception to ambush us with? <g>
>>>
>>> I think that sort of issue could be handled by having game-dependent
>>> Comparator<Card,Card> implementations, rather than making Card
>>> Comparable.
>>
>> A comparator might have a hard time declaring "Ace is lower
>> than Deuce" and "Ace is higher than Deuce" simultaneously ...
>>
>> And then, there are games where two identical ranks in the
>> same hand can have different values. With A-A-9, for example, a
>> Blackjack player would get the desired total of 21 by counting
>> one Ace as a 1 and the other as an 11. (This appears to be the
>> class of game the O.P. is interested in.)
>
> If the logic can be described precisely, then it can be
> implemented in code.
Yes. But my principal point in all of this is that it cannot
always be implemented in *simple* code. Given the variety of card
games, it is folly to try to capture the notion of "card" in a
single, game-independent way. The same holds true for many other
problem domains as well: It is fruitless to model "a card" or
"a stock market" or "a person" in isolation from the model in
which the card/market/person will be represented.
The fundamental strength of O-O is that *sometimes* such
problem-oblivious models can be created, and *sometimes* the
next problem in line will be able to re-use the model. The
fundamental fallacy of O-O zealots is that such models are
independent of the problem; they nearly always aren't.
> I somewhat suspect that stuff like this will not result
> in pretty code.
(Shrug.) If you want to model something, you choose your
own level of fidelity. An old story tells of an engineer, a
physicist, and a mathematician tasked with finding the wind
resistance of a proposed design for a railway locomotive. The
engineer suggests building a full-scale wind tunnel, putting a
mock-up of the locomotive inside, and measuring the drag with a
simple spring scale.
"Wasteful!" cries the physicist. "The whole thing is fully
explained by the following enormous system of partial differential
equations, for which we can get numerical solutions with only six
and a half months' time on the world's largest supercomputer."
"Tut-tut," says the mathematician. "You empiricists are all
alike, rushing to measurements and approximations when a simple
grasp of theory would render everything clear to the suitably
rigorous mind. Now attend: Consider a spherical train ..."
(You think I'm kidding? There exist astrophysical models of
stellar structure in *one* dimension: radial distance from center.
So much for angular momentum and solar flares, eh?)
--
Eric Sosman
esosman@comcast-dot-net.invalid
[toc] | [prev] | [next] | [standalone]
| From | lipska the kat <lipskathekat@yahoo.co.uk> |
|---|---|
| Date | 2012-12-19 09:33 +0000 |
| Message-ID | <jIqdnSe1lIqXF0zNnZ2dnUVZ7qidnZ2d@bt.com> |
| In reply to | #20505 |
On 19/12/12 02:07, Eric Sosman wrote: > On 12/18/2012 8:11 PM, Arne Vajhøj wrote: [snip] >> If the logic can be described precisely, then it can be >> implemented in code. > > Yes. But my principal point in all of this is that it cannot > always be implemented in *simple* code. Given the variety of card > games, it is folly to try to capture the notion of "card" in a > single, game-independent way. OK, I guess we got off on the wrong foot so I'll try again. I'm not trying to be condescending. I'm genuinely interested in your response. Can we agree that the names we give things help our understanding of what those things are supposed to represent ? In our world, it almost always the case that, sooner or later, someone who was not present during the design phase of our system will need to understand it in order to maintain it. Good names for system concepts help. If we think of a Card in the 'games played with cards' universe then, unless I've missed something a card is a small piece of cloth or cardboard that has some numbers, pictures or symbols on one or both sides. Maybe a better name would be PlayingCard The concept of a PlayingCard is fixed in our collective memory by virtue of the experiences we have of PlayingCards in our lives. Of course different cultures use cards in different ways to play different games but the point is, if you ask anyone on the planet what a PlayingCard is them I suggest that the basic concept will always be there. Can we also agree that any system needs a starting point and a good starting point might be a name that seems to capture at least part of what our system is supposed to do. If we agree on these few simple principles then I'd be interested to know what name you might use for your starting point if not PlayingCard (or Card). I can't think of a card game that does not use PlayingCards of one sort or another. One might argue that Tarot is not a game yet uses Cards. This might mean that PlayingCard is unsuitable, so we fall back to Card with PlayingCard a possible later specialization. If the base abstraction is not Card then what else might describe what a Card is better than 'Card' lipska -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun
[toc] | [prev] | [next] | [standalone]
Page 1 of 5 [1] 2 3 4 5 Next page →
Back to top | Article view | comp.lang.java.programmer
csiph-web