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 trial

Python Object-Oriented Python Dice Roller Yatzy Scoring

nicole lumpkin
PLUS
nicole lumpkin
Courses Plus Student 5,328 Points

YatzyScoreSheet class like a middleman?

So the YatzyScoreSheet class isn't a list or some other object that holds items. It doesn't even have attributes. My questions are:

  1. Is it just a place to group together methods that take in (as arguments) and act on YatzyHand instances?
  2. Why wouldn't we want to implement all scoring methods in the YatzyHand class itself?

Thanks :)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Great question! You are correct. YatzyScoreSheet inherits from the simple object class by default. It does not have at attributes. Additionally, all of the methods have a self parameter but it is never referenced. This implies these methods could have been decorated with @staticmethod and not include the "self" parameter.

Yes, YatzyScoreSheet is a basic place to group together all the scoring methods. Since every one of its methods expect to operate on a YatzyHand object, it would make just as much sense to include these methods inside of the YatzyHand class. One pitfall to the using YatzyScoreSheet to hold all the method is there is no guarantee that the hand passed in is an actual YatzyHand-class object.

One one argument for not putting all the YatzyScoreSheet methods into the Hand class is to keep YatzyHand class from being too cluttered.

Another way to code it is to create YatzyScoreSheet as a mixin. This involves not having a "hand" parameter in the methods and relying on the self to point at the YatzyHand object. Then the YatzyHand could be coded as:

class YayzyHand(YatzyScoreSheetMixin, Hand):

This effectively puts the methods "inside" of YatzyHand, but also keeps the scoring organized in a separate file.

Post back if you need more help. Good luck!!!

nicole lumpkin
nicole lumpkin
Courses Plus Student 5,328 Points

Wow Chris Freeman , creating YatzyScoreSheet as a mixin just blew my mind!!! I'll go play and I'll write back if I need help. :) Thanks again!!!

Great Idea. Cleans up code nicely.