What are the main issues I can come across if I choose to use classmethod over Inheritance in Python? A (silly) example would be:
class Pizza(object):
def __init__(self, ingredients):
self.ingredients = ingredients
self.cooked = False
def cook(self):
print "cooking"
self.cooked = True
# A pepperoni pizza using a factory method
@classmethod
def Pepperoni(cls):
return cls("pepperoni")
# An onion pizza inheriting from Pizza base class
class Onion(Pizza):
def __init__(self):
ingredient = "onion"
super(Onion, self).__init__(ingredient)
I know that
- I cannot (easily) add custom methods to Pepperoni
- I cannot make Pizza an abstract base class
anything else?