
nicole lumpkin
Courses Plus Student 5,328 PointsYatzyScoreSheet 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:
- Is it just a place to group together methods that take in (as arguments) and act on YatzyHand instances?
- Why wouldn't we want to implement all scoring methods in the YatzyHand class itself?
Thanks :)
1 Answer

Chris Freeman
Treehouse Moderator 61,988 PointsGreat 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
Courses Plus Student 5,328 Pointsnicole lumpkin
Courses Plus Student 5,328 PointsWow 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!!!
Anthony Albertorio
22,168 PointsAnthony Albertorio
22,168 PointsGreat Idea. Cleans up code nicely.