Skip to content

Commit cc33e9c

Browse files
committed
Fix textual errors
1 parent 41a2e54 commit cc33e9c

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed

source-code/object-orientation/avoiding_class_hierarchies.ipynb

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
{
22
"cells": [
3-
{
4-
"cell_type": "markdown",
5-
"metadata": {},
6-
"source": [
7-
"# Avoiding class hierarchies"
8-
]
9-
},
103
{
114
"cell_type": "markdown",
125
"metadata": {},
@@ -23,7 +16,7 @@
2316
},
2417
{
2518
"cell_type": "code",
26-
"execution_count": 37,
19+
"execution_count": 1,
2720
"metadata": {},
2821
"outputs": [],
2922
"source": [
@@ -34,7 +27,7 @@
3427
"cell_type": "markdown",
3528
"metadata": {},
3629
"source": [
37-
"## Duck typing"
30+
"# Duck typing"
3831
]
3932
},
4033
{
@@ -53,7 +46,7 @@
5346
},
5447
{
5548
"cell_type": "code",
56-
"execution_count": 47,
49+
"execution_count": 2,
5750
"metadata": {},
5851
"outputs": [],
5952
"source": [
@@ -71,7 +64,7 @@
7164
},
7265
{
7366
"cell_type": "code",
74-
"execution_count": 48,
67+
"execution_count": 3,
7568
"metadata": {},
7669
"outputs": [],
7770
"source": [
@@ -96,7 +89,7 @@
9689
},
9790
{
9891
"cell_type": "code",
99-
"execution_count": 49,
92+
"execution_count": 4,
10093
"metadata": {},
10194
"outputs": [],
10295
"source": [
@@ -112,7 +105,7 @@
112105
},
113106
{
114107
"cell_type": "code",
115-
"execution_count": 50,
108+
"execution_count": 5,
116109
"metadata": {},
117110
"outputs": [
118111
{
@@ -140,14 +133,7 @@
140133
"cell_type": "markdown",
141134
"metadata": {},
142135
"source": [
143-
"An alternative way to implement this, and to avoid "
144-
]
145-
},
146-
{
147-
"cell_type": "markdown",
148-
"metadata": {},
149-
"source": [
150-
"## Mix-in"
136+
"# Mix-in"
151137
]
152138
},
153139
{
@@ -159,7 +145,7 @@
159145
},
160146
{
161147
"cell_type": "code",
162-
"execution_count": 52,
148+
"execution_count": 6,
163149
"metadata": {},
164150
"outputs": [],
165151
"source": [
@@ -176,12 +162,12 @@
176162
"cell_type": "markdown",
177163
"metadata": {},
178164
"source": [
179-
"The `Duck` and `Timer` classes now inherit from `SoundMaker`, but"
165+
"The `Duck`, `Timer` and `Dog` classes now inherit from `SoundMaker`, but `Dog` doesn't define its sound attribute."
180166
]
181167
},
182168
{
183169
"cell_type": "code",
184-
"execution_count": 54,
170+
"execution_count": 7,
185171
"metadata": {},
186172
"outputs": [],
187173
"source": [
@@ -196,7 +182,7 @@
196182
},
197183
{
198184
"cell_type": "code",
199-
"execution_count": 55,
185+
"execution_count": 8,
200186
"metadata": {},
201187
"outputs": [],
202188
"source": [
@@ -211,7 +197,7 @@
211197
},
212198
{
213199
"cell_type": "code",
214-
"execution_count": 56,
200+
"execution_count": 9,
215201
"metadata": {},
216202
"outputs": [],
217203
"source": [
@@ -225,7 +211,7 @@
225211
},
226212
{
227213
"cell_type": "code",
228-
"execution_count": 58,
214+
"execution_count": 10,
229215
"metadata": {},
230216
"outputs": [],
231217
"source": [
@@ -234,7 +220,7 @@
234220
},
235221
{
236222
"cell_type": "code",
237-
"execution_count": 59,
223+
"execution_count": 11,
238224
"metadata": {},
239225
"outputs": [
240226
{
@@ -251,19 +237,26 @@
251237
" print(f'{type(item)} says {item.make_sound()}')"
252238
]
253239
},
240+
{
241+
"cell_type": "markdown",
242+
"metadata": {},
243+
"source": [
244+
"Since the `Dog` has no `_sound`, the mix-in method raises an exception."
245+
]
246+
},
254247
{
255248
"cell_type": "code",
256-
"execution_count": 60,
249+
"execution_count": 12,
257250
"metadata": {},
258251
"outputs": [
259252
{
260253
"name": "stderr",
261254
"output_type": "stream",
262255
"text": [
263256
"Traceback (most recent call last):\n",
264-
" File \"<ipython-input-60-1c825f3b7991>\", line 3, in <module>\n",
257+
" File \"<ipython-input-12-1c825f3b7991>\", line 3, in <module>\n",
265258
" print(dog.make_sound())\n",
266-
" File \"<ipython-input-52-918cd6c589ba>\", line 7, in make_sound\n",
259+
" File \"<ipython-input-6-918cd6c589ba>\", line 7, in make_sound\n",
267260
" raise ValueError(f'{type(self)} does not make sound')\n",
268261
"ValueError: <class '__main__.Dog'> does not make sound\n"
269262
]
@@ -294,9 +287,9 @@
294287
"name": "python",
295288
"nbconvert_exporter": "python",
296289
"pygments_lexer": "ipython3",
297-
"version": "3.7.0"
290+
"version": "3.9.5"
298291
}
299292
},
300293
"nbformat": 4,
301-
"nbformat_minor": 2
294+
"nbformat_minor": 4
302295
}

0 commit comments

Comments
 (0)