Wrapping – aggregation and composition

Wrapping is a way to understand a collection. It can be a class that is an aggregate of independent objects. It's also a composition that wraps an existing list, meaning that the underlying Card objects will be shared by a list collection and a Deck collection.

  1. Define the independent collection. It might be a built-in collection, for example, a set, list, or dict. For this example, it will be a list that contains the cards:
        
domain = [Card(r+1,s) for r in range(13) for s in SUITS] 
  1. Define the aggregate class. For this example, the name has a _W suffix. This is not a recommended practice; it's only used here to make the distinctions between class definitions more clear.
 Later, we'll see a slightly ...

Get Modern Python Cookbook 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.