Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with some code 1. Dessert Shop Part 6: Interfaces and Multiple Inheritance Problem In this part of the project, we contrast adding

I need help with some code
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
1. Dessert Shop Part 6: Interfaces and Multiple Inheritance Problem In this part of the project, we contrast adding a new property that every object has versus adding a mixin property that only that only some objects have. You witl add two features: - Packaging identify what kind of packaging a dessert item is placed in. Alt items of a simitar type will use the same type of packaging. Packaging types will show up on the receipt. We will use straightforward inheritance to implement this one. - Freezec identify items that need to be kept cold versus items that don't. We don't chill candy, but we do chill Cookies, ice Cream and Sundaes. Changes to Dessertltem class Add an attribute called packaging to Dessertitem class. Do not change the constructor signature, because you can create a dossert and add packaging tater. Default value is Changes to the Concrete Subclasses of Dessertitem - set the superclass packaging type within the constructor; the default value for each respective type is as follows: - for Candy. packaging = "Bag" - for Cookie: packaging = "Box" - for lce Cream: packaging = "Bowl" - for Sundae: packaging = "Boat" - modify the magic method to include the packaging type as shown in the example run Freeze Protocol class There are several ways to implement the Freeze feature. One way to achieve this in Python is to use Protocol classes, which were discussed in class. Protocol classes allow is to define an interface, AKA a protocol, and use static type-checking via pyry. to verify that objects satisfy the interface - without classes having to declare that they satisfy the interface or subclass anything. You can explicitly declare that a class subclasses a Protocol class, but it is not required for the 1. Dessert Shop Part 6: Interfaces and Multiple inheritance allow us to define an interface, AKA a protocol, and use static type-checking via to verify that objects satisfy the interface - without classes having to declare that they satisfy the interface or subclass anything. You can explicitly declare that a class subclasses a Protocol ciass, but it is not required for the purpose of type checking The Freeze protocol defines the following methods: - chill after this method is cailed should return the string "chilling": thaiwe after this method is called tesceritureis should return the string "thawing". temperatured Return the temperature of the temi initially an tem is always "thawing". Define the Freeze protocot in file Freezer class The Freezer class defines the following mechods - put(self, item, Feozer) -> put an item in the frepzer Call the item's method. - take(self, item_name: str) take the first itemithat matches of the specifed name out of the freezer. Call the itemis inniil method. You can assume that if an item is asked for it is already in the freozer. Define the Freezer class in fle Changes to dessertshop main() Before your code tries to create and fulfal an ordec, croate a freezer and stockit. with at least enough freezable items to satisty the order. As freezable items are ordered. remove them from the freezer. The biggest difference this makes in your code is - You create dessert objocts before you use them to fulfil an order. - One strategy you can ise ta pull the correct dessert object type out of the fridge is to give the objects a generic name lioe "Cocive' that matches the byge of the dessert selected 1. Dessert Shop Part 6: Interfaces and Multjple inheritance if an item doesn t exist in the rnage jyou ran out ot premade items) then create one from scratch. Refactoring Dessert Shop Code You may find it educational and helptul at this point to refactor your starting code. for Part 6 into the following modules: - test, dessert,py -> import whatever code is being tested such as desserts, packaging and freezing. - dessertshop py application drver code which is mingr, the prompt functions and any other code related to progam input and output. dossert py your dessert class hierarcty code goes here, except what must be in Is this refactoring required? Strictly na, but we would really tike you to do it because you need to be comfortable with it in reat ufe. The split out of the Freeze protocol into the freezer module is required. Test Cases Add automated test casos to test packaging for aach concrete dessert bype. Add automated test cases to test the freezer protocol for each concrete dessert type. To do this, turn on runtime type checierg for Freezer using the decarator explained in the slides for Modile 5. which gives you access to and for Protocol classes Example Scenario 1: Candy 2. Cookie 3. lce Cream 4. Sunday What would you tike to add to the orden (1-4, Enter for done); 2 Enter the type of cookle: Oatmeal Rakin Enter the quartity purchssed 4 Enter the price per donen 3,45 1i Caridy 2 Cooke 3: lee Cream 4. Sunday What would you the to add to the order? al-4. Enter for donel 1. Dessert Shop Part 6: Interfaces and Multiple Inheritance Grading Rubric packaging inheritod attribute is adoed to Dessertitems as descnibed Freeze protocol class has been implemerted as described Cookies, lceCream and Sundae classes implicitly implement the Freeze protocol and pass type checking The receipt output has been updated to include the new infornation as shown Test cases for classes Candy, Cosce, laeCremn and Sundae have been updated to test packaging Test cases for classes Candy. Cooke, iceCream and Sundae have boen updated to tert the Freezer Protocol. Regrestion tests all pass

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions