You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<pclass="fragment">See <ahref="http://calebsmith.github.io/gdi-intro-python/examples/mobile.py">mobile.py</a> for a more complete example.</p>
220
220
</section>
221
221
222
+
<section>
223
+
<h3>What's Super about Super</h3>
224
+
<p><strong>super</strong> is often helpful when writing methods that override the method of the parent class</p>
225
+
<pre><codecontenteditableclass="fragment python">
226
+
class BoundedMobile(Mobile):
227
+
"""
228
+
An object with an x, y position, and methods for moving
229
+
The x, y position must be within bounds
230
+
"""
231
+
232
+
def move_up():
233
+
super(BoundedMobile, self).move_up()
234
+
if self.y <0:
235
+
self.y = 0
236
+
</code></pre>
237
+
<pclass="fragment">The call to super() takes the name of the child class, followed by self. This is followed by the method call and any arguments to pass to it</p>
238
+
</section>
239
+
222
240
<section>
223
241
<h3>Composition</h3>
224
242
<p>Classes can also use the technique of <strong>composition</strong></p>
0 commit comments