June 2019
Beginner to intermediate
770 pages
19h 24m
English
The following is a wrapper design that contains an internal collection:
class Deck: def __init__(self) -> None: self._cards = [card(r + 1, s) for r in range(13) for s in iter(Suit)] random.shuffle(self._cards) def pop(self) -> Card: return self._cards.pop()
We've defined Deck so that the internal collection is a list object. The pop() method of Deck simply delegates to the wrapped list object.
We can then create a Hand instance with the following type of code:
d = Deck() hand = [d.pop(), d.pop()]
Generally, a Facade design pattern or wrapper class contains methods that delegate the work to the underlying implementation class. This delegation can become wordy when a lot of features are provided. For a sophisticated ...
Read now
Unlock full access