Aaron
Aaron

Reputation: 4480

Design a generic card deck

I have been asked this question twice at interviews. How to design a generic card deck. The deck can include magic cards, uno cards, and regular playing cards. What classes, methods, and attributes should I use?

Upvotes: 0

Views: 150

Answers (1)

Jacob Boyd
Jacob Boyd

Reputation: 680

You could really go into depth with this kind of question, but you should always start with a super class of Card. Giving Card/Deck the basic attributes of all cards, lets say height and width, deckSize to hold the number of cards, and shuffle() method to shuffle the deck.

Then you will want to create, MagicCards, UnoCards, and PlayingCards(/PokerCards?) classes to subclass Card/Deck. Giving them different attributes and methods or behaviors based on their class. Like PlayingCards will need a suite attribute. Magic cards will need a match(Card card) or check(Card card) to see if the card the user picked is the same(Simple card trick).

Upvotes: 1

Related Questions