User Tools

Site Tools


python:about_python:about_python_iv

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
python:about_python:about_python_iv [2013/07/05 06:19]
mithat created
python:about_python:about_python_iv [2019/06/21 23:09]
mithat [Inheritance in Python]
Line 33: Line 33:
 One of the advantages of implementing classes with inheritance is **code reuse**. ​ Almost all class-based object oriented languages let you define derived classes //without having to re-write the base class code//. The idea is that you write the base class code //once//. Then when you write the derived classes, you add only whatever new code is required for the derived class or new definitions for old code that must be **overridden**. One of the advantages of implementing classes with inheritance is **code reuse**. ​ Almost all class-based object oriented languages let you define derived classes //without having to re-write the base class code//. The idea is that you write the base class code //once//. Then when you write the derived classes, you add only whatever new code is required for the derived class or new definitions for old code that must be **overridden**.
  
-Since you do not need to rewrite the code that is common to both base and derived classes, you end up writing less code. But even more important, when you fix a bug in the base class, it automatically propagates ​down to the derived classes.+Since you do not need to rewrite the code that is common to both base and derived classes, you end up writing less code. But even more important, when you fix a bug in the base class, it automatically propagates to the derived classes.
  
 === Inheritance and polymorphism === === Inheritance and polymorphism ===
Line 43: Line 43:
 To demonstrate the use of inheritance in Python, we are going to create a specialized version of ''​ClickerCounter''​ called ''​ClickUpDown''​. To demonstrate the use of inheritance in Python, we are going to create a specialized version of ''​ClickerCounter''​ called ''​ClickUpDown''​.
  
-<img src="​images/​clickupdown.png" title="​ClickUpDown heirarchy"​ alt="​ClickUpDown heirarchy"​ />  ​+{{:​python:​about_python:​clickupdown-tree.png?​direct|}} ​
  
 In addtion to the two buttons found on a ''​ClickerCounter''​ (for incrementing and resetting the count), a ''​ClickUpDown''​ object will add another that resets the count. In terms of a Python model, a ''​ClickUpDown''​ is identical to a ''​ClickerCounter''​ except that it has an additional method: ''​click_down''​. In addtion to the two buttons found on a ''​ClickerCounter''​ (for incrementing and resetting the count), a ''​ClickUpDown''​ object will add another that resets the count. In terms of a Python model, a ''​ClickUpDown''​ is identical to a ''​ClickerCounter''​ except that it has an additional method: ''​click_down''​.
python/about_python/about_python_iv.txt · Last modified: 2019/06/21 23:09 by mithat