Skip to content

Instantly share code, notes, and snippets.

@dketov
Created December 14, 2011 05:15
Show Gist options
  • Select an option

  • Save dketov/1475369 to your computer and use it in GitHub Desktop.

Select an option

Save dketov/1475369 to your computer and use it in GitHub Desktop.
Наследование
# -*- 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