Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't believe you are really asking the right question here. How to represent your card should be a matter determined by what you want to do with your cards; By answering the question of how to represent your card now, you're automatically constraining yourself in the ways which you can solve other more interesting/challenging problems which you'll be coming up against later.</p> <p>The kinds of things you really ought to think about are how you are going to implement the behaviour of your program. for example</p> <ul> <li><p>What will happen when a "card" is dealt? Do you want to represent a card being physically moved between the entities which hold those cards? (for example, the Deck, a Player's hand, a discard pile, the table, etc), or do you want those entities to merely reference a central repository of cards? or perhaps use an entirely separate counting mechanism?</p></li> <li><p>How are you going to "order" cards? The games which you choose to implement may have different rules (e.g. Ace Low or High? do royal suits all have the same value? will there be a trump card?) These might be decisions which are determined on a game-by-game basis, and even changed during the game itself, therefore simply having a single definition of a card based on it's ordering may not prove to be a good abstraction.</p> <ul> <li><p>What kinds of behaviour and game rules are you trying to represent which will depend on the card? Will the card itself have any dependencies?</p></li> <li><p>Is the card going to be involved in user interaction, or is it purely a logical object used by the parts of your program which defines the card game(s)?</p></li> <li><p>Have you thought about the possibility of using different kinds of cards? You mentioned a class in your original question, but if a card is going to define any kind of state, behaviour or interact with other classes, then you might first want to think about defining a Card interface before worrying about the details.</p></li> </ul></li> </ul> <p>As a direct answer to your question - I don't personally think that you've supplied enough information for the answer to be anything other than an opinion based upon guesswork and personal preference; that's ok because usually it's difficult to come up with all the answers before you've begun implementation. You might want to try all three and see which best suits your needs. Don't constrain your design by making these kinds of decisions up front.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload