Skip to content

Commit 5199bff

Browse files
committed
Pass type instead of string
1 parent 5dd018c commit 5199bff

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ share common properties to the abstracts coins and products.
2121

2222
We must also model our vending machine and define actions on it:
2323
- `+ insert_coin(coin: Coin)`
24-
- `+ buy_product(product: str) -> Product`
24+
- `+ buy_product(product: type) -> Product`
2525
- `+ get_balance() -> int`
2626
- `+ get_change() -> List[Coin]`
2727

@@ -108,7 +108,7 @@ parent class(es) as arguments.
108108
| `coins: List[Coin]` |
109109
| `purchases: List[Product]` |
110110
| `insert_coin(coin: Coin)` |
111-
| `buy_product(product: str) -> Product` |
111+
| `buy_product(product: type) -> Product` |
112112
| `get_balance() -> int` |
113113
| `get_change() -> List[Coin]` |
114114

@@ -121,10 +121,21 @@ parent class(es) as arguments.
121121
- When the function insert_coin() is called, store the inserted coin a list on
122122
the object
123123

124-
### .buy_product(product: str) -> Product
124+
### .buy_product(product: type) -> Product
125125

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()`
128139

129140
- If the vending machine balance is less than the cost of the product, a
130141
custom exception called `InsufficientFunds` should be raised.

0 commit comments

Comments
 (0)