Yet more __init__() techniques

We'll take a look at a few other, more advanced __init__() techniques. These aren't quite so universally useful as the techniques in the previous sections.

The following is a definition for the Player class that uses two Strategy objects and a table object. This shows an unpleasant-looking __init__() method:

class Player:    def __init__(        self,         table: Table,         bet_strategy: BettingStrategy,         game_strategy: GameStrategy    ) -> None:        self.bet_strategy = bet_strategy        self.game_strategy = game_strategy        self.table = table    def game(self):        self.table.place_bet(self.bet_strategy.bet())        self.hand = self.table.get_hand()        if self.table.can_insure(self.hand):            if self.game_strategy.insurance(self.hand):                self.table.insure(self ...

Get Mastering Object-Oriented Python - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.