You do not need to use classes to use classes (unless you use Java)
As I approach classes, I first think about what โobjectโ or โthingโ I will need, and then define the properties and methods that will determine this thing. If I'm going to create multiple instances of the same thing, then the class is useful. If I need only one instance, then most likely there will be enough module or global variable.
For example, in your example, you really don't need classes. However, if you are doing something like supporting multiple decks for your game, you need to define a Deck class that can contain and control all the information about its own cards.
Think about poker itself - how does it work?
You have a dealer, you have players, the dealer has one or more decks of cards. The dealer shuffles and then passes the cards to the players and the table. How would you like to define each of these processes as objects?
I would look at a real example and split it into its reusable parts, and this will become your class. So, for example, I would probably look at him and say:
class Deck(object): """ class for managing a deck of cards """ class Player(object): """ defines properties and methods that an individual player would have """ def __init__( self ): self._cards = []
So, etc.
All of this code is usually pseudo-code to illustrate how to visualize a way to smash things mentally. In fact, the easiest way is to think about a real script and write in plain English how it works, and then the classes will begin to visualize themselves.
source share