假设我们正在编写一个简单的扑克游戏。
class Card
{
public:
Card(Suit s, Rank r);
enum Suit getSuit();
enum Rank getRank();
void printCard();
private:
Suit suit;
Rank rank;
};
class Deck
{
public:
Deck();
/* either friend class Dealer; or should Dealer's class function that
manipulates deck assigned here? or make private deck data public?? */
private:
std::vector<Card> deck;
};
class Player
{
public:
int raise();
int bet();
Card fold();
void check();
private:
Card hand;
int money;
};
class Dealer
{
public:
Dealer();
void DealCardsToPlayers(Deck& d);
void Shuffle(Deck& d);
Player evaluateWinner();
private:
int collectPot();
int pot;
};
在现实世界中,牌组本身不知道其行为或方式,发牌人将处理牌的行为和方式。但是我不确定这在编程世界中是否是一个好的设计。
操纵Deck数据的类函数应该在哪里?