The assignment contains these instructions:
Part II – Factory Class
This class acts as the base class for other concrete Fruitclasses, like Orange and Apple. As the title hints at, this class will also serve as the factory for those derivative classes. This class should have the following methods:
• __init__(self)
o This method is mostly a placeholder. Print a message when it is called while debugging.
• price(self)
o Returns the price of the item.
o This is also a placeholder for use by derived classes. It only needs to return 0.
• prepare(self)
o This method is a placeholder for use by derived classes.
o In derived classes, this method acts as a façade that encapsulates the complex process
for preparing fruits.
**• order_fruit(fruit_type) # Notice no 'self'
o This method acts as the factory method for making fruit objects.
o This method should be static so mark it with the @staticmethod decorator.
o Here’s the process for kicking off the factory:
▪ Make sure fruit_type is a string and trim and convert it to lower case
▪ Create the object of the type called for by the string
• So if it is “orange”:
o fruit = Orange()
▪ Once your fruit object is created, you will call its prepare() method
I need help with the part in bold. I have this:
class Fruit():
def __init__(self):
print(f"Fruit.__init__")
def price(self):
return 0
def prepare(self):
print(f"Preparing {fruit}")
@staticmethod
def order_fruit(fruit_type):
fruit= str(fruit_type.lower().strip())
prepare(fruit)
#I can't figure out how to get it to call, for example, Orange.prepare()
I might be misunderstanding the instructions.