@@ -21,7 +21,7 @@ share common properties to the abstracts coins and products.
21
21
22
22
We must also model our vending machine and define actions on it:
23
23
- ` + insert_coin(coin: Coin) `
24
- - ` + buy_product(product: str ) -> Product `
24
+ - ` + buy_product(product: type ) -> Product `
25
25
- ` + get_balance() -> int `
26
26
- ` + get_change() -> List[Coin] `
27
27
@@ -108,7 +108,7 @@ parent class(es) as arguments.
108
108
| ` coins: List[Coin] ` |
109
109
| ` purchases: List[Product] ` |
110
110
| ` insert_coin(coin: Coin) ` |
111
- | ` buy_product(product: str ) -> Product ` |
111
+ | ` buy_product(product: type ) -> Product ` |
112
112
| ` get_balance() -> int ` |
113
113
| ` get_change() -> List[Coin] ` |
114
114
@@ -121,10 +121,21 @@ parent class(es) as arguments.
121
121
- When the function insert_coin() is called, store the inserted coin a list on
122
122
the object
123
123
124
- ### .buy_product(product: str ) -> Product
124
+ ### .buy_product(product: type ) -> Product
125
125
126
- - The product argument may be one of the following values: "drink", "candy",
127
- "chips". Any other value should raise a ` ValueError ` exception.
126
+ - The product argument may be one of the following types: ` Drink ` , ` Candy ` ,
127
+ or ` Chips ` , but be flexible enough to accept other ` Product ` types. Any other
128
+ value should raise a ` ValueError ` exception. Note: these are the ` Product `
129
+ classes we've defined, and ** not their instances** .
130
+
131
+ E.g.
132
+ ``` python
133
+ machine = VendingMachine()
134
+ machine.buy_product(products.Drink) # Good: This is a type
135
+ machine.buy_product(products.Drink()) # Bad: This is an instance
136
+ ```
137
+
138
+ This is the same difference as the type ` int ` and the instance ` int() `
128
139
129
140
- If the vending machine balance is less than the cost of the product, a
130
141
custom exception called ` InsufficientFunds ` should be raised.
0 commit comments