Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAmeen Noushad
2,799 Pointscan someone explain, why we cant use one class to do finish this challenge? Why we should have 2 different class?
I'm confused. What's the use of having 2 class in this particular function? how can i identify the need of two classes or more?
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsGood question. It is entirely possible to solve this in a single class. In this case, I would name the Hand class specific to the type of Game Hand.
It is good practice to divide up object structure at hierarchical boundaries where the attributes and methods at each level would operate differently. For the card, it could be a methods to select values and compare itself to other cards. For the hand, the method to compare to other hands would be different that the card to card comparisons. The hands would also have methods to generate new hands, select cards, and so on.
As an extension, the card and the hand class could be more generic. Then you could create a derivative hand class that would inherit from the base Hand class, such as, PokerHand, Crazy8sHand, Pinochle, etc, Also the Cards could take a Deck class argument that would specify the range of possible cards. This deck class could have a shuffle method and a __next__
method offer up the next card in the deck.
Ameen Noushad
2,799 PointsAmeen Noushad
2,799 PointsThanks for your help. :)