Question: Python - I need help with setting up a singleton. I am struggling with the functions, especially with the two variables _orders and _total_sales, how

Python - I need help with setting up a singleton. I am struggling with the functions, especially with the two variables _orders and _total_sales, how do I build it so that it keep the orders tracked and their cumulative price? and the __str__ function, how to build it so that it informs how many orders were placed?!?! I am lost with the order_food function, should I just leave it blank and add later? Please help, see my attempts below.

Python - I need help with setting up a singleton. I amstruggling with the functions, especially with the two variables _orders and _total_sales,how do I build it so that it keep the orders tracked

SCRIPT:

class Restaurant(): def __new__(cls, *args, **kwargs): cls.name = def __str__(self): msg = cls.name def order_food(self, food_type):

Part I - Setting up the Singleton The singleton class for this lab is called Restaurant. The idea is that there can only ever be one restaurant that the customer goes to. It will have at least the following methods: _new_(cls, *args, **kwargs) This method intercepts any call where a new Restaurant is being created. o Use the Singleton creational design pattern example to ensure only one instance of Restaurant is ever created and return that instance. Optionally, assign two variables to that instance called _orders and _total_sales that will keep track of the number of orders placed in the restaurant and their cumulative price. _str_(self) -vy.IL return a string that informs the user how many orders were placed and how much money the restaurant brought in. o Use the variables discussed in the __new_() method. order_food(self, food_type) o This method is the gateway to the factory design pattern. o For now, the only thing you can effectively put in this method is reference to code that will be added later. Looking forward, it will call the static order_food method of the Food class, passing it food_type as its only argument. o Additionally, this is where you will have to alter the _orders and _total_sales variables 8 9 class Restaurant(): def __new_(cls, *args, **kwargs): cls.name 10 11 12 13 14 15 16 17 def _str_(self): msg cls.name 18 19 20 def order_food(self, food_type)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!