As mentioned in #3, it's a good thing when you have some physical objects to deal with, because they usually map fairly well to software objects. In this case, the obvious physical objects are:
Players Cards DeckThose cover the absolute minimum of things you need to play poker. You might go further, and think of
Hand Table
I think that pretty much covers all the basic object types we'll need. Now, depending on just how object-crazy you are, you may want to narrow down some of these objects. Let's look at some of the drawbacks to the above objects
It really depends on your overall game handling. If you know you're only going to look at cards in one, maybe two functions, then you could use the int representation. On the other hand, if you are going to be looking at card values all over the place, it makes things much cleaner to have a Card class, with easy-to-read methods like Card.getSuit() and Card.getValue()
On the other hand, if you were writing an extremely simplified poker "back end", then having a Table object would be overkill.
PlayerObj # of methods =5 HandObj # of methods =5but
PlayerHandObj # of methods =8you have probably reduced complexity somewhat. But that's just a rough guideline. The bottom-line measure should always be: which seems simpler and neater??
The counterpoint to merging them (you knew there had to be one, right? :-) would be if you were planning on doing interesting things with Players, that had nothing to do with Hands, and Hands were more complex than
class Hand { Card[5]; }
In that case, you have two objects that are linked to each other, but have a fair amount of code with nothing in common. Then, the "neatness factor" comes into play. Keep separate Hand and Player objects.
In real life, a Player holds a Hand. It makes a lot of sense to have our virtual objects act similarly. But does that mean we should start writing things like
if(Player.Hand.Card1 == x)...NO!
The above is a strong temptation to those who may be used to programming with "structs". But it makes for bad object programming. The whole point of having objects, is to have that object manage its own data. If you go directly to a player's hand, you're stopping the player from acting like a true object. Think of it this way: if you reached across a table to pull a card from someone else's hand, they wouldn't like it!
So, the right thing to do is make sure the Player object has an adequate amount of Hand manipulation hooks. Things that immediately spring to mind are:
Player.numberOfCards(); Player.showCards(); Player.takeCard(); Player.exchangeCards();Note how these are all things that "players" would be interested in, with a real game of poker.
Next section: Summary of Game-plan