mercredi 4 janvier 2017

When is it appropriate to use different classes rather than different objects?

I am making a Spyfall game, a game where all players are at a certain location, and their roles depend on which location they are at. Thus, each Location has their own set of roles that the players randomly receive.

Currently, there are about 27 locations, like the Casino. The Casino has the roles of the Bartender, Gambler, Dealer, etc.

When I create a list of my locations to use in my game, should I create a general Location class:

class Location:
    def __init__(self, name, *roles):
        self.name = name
        self.roles = roles

and use constructors with different parameters like

 Location(name="Passenger Airplane", "Economy Class Passenger"...so on
 Location(name="Bank Robbery", "Customer", ...so on

or should I create classes inheriting from Location and hard-code the values:

class Airplane(Location):
    def __init__(self):
        self.name = "Airplane", etc

In addition, I want to add a list of facts to each Location (e.g WWII was in the 1940s), and to me, putting that list in the constructor seems a bit much.

Assuming I use classes rather than use constructors, should I use a factory design pattern?

Aucun commentaire:

Enregistrer un commentaire