Created
December 14, 2011 05:15
-
-
Save dketov/1475369 to your computer and use it in GitHub Desktop.
Наследование
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- encoding: utf-8 -*- | |
| """ | |
| Наследование | |
| """ | |
| def rotate_tires( car ) : | |
| for i in range(1, car.tire_count()) : | |
| print "Moving tire from " + str(i) | |
| car.set_tire( i+1 ) | |
| print "Moving tire from " + str(car.tire_count()) | |
| car.set_tire( 1 ) | |
| class Car(object) : | |
| def __init__(self) : | |
| self.number_of_tires = 4 | |
| def set_tire( self, nPos ) : | |
| print "Setting tire into position: " + str(nPos ) | |
| def tire_count(self) : | |
| return self.number_of_tires | |
| class Hybrid(Car) : | |
| def __init__(self) : | |
| self.number_of_tires = 3 | |
| c = Car() | |
| rotate_tires(c) | |
| h = Hybrid() | |
| rotate_tires(h) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment