Skip to content

Instantly share code, notes, and snippets.

@j10sanders
Last active October 8, 2015 15:38
Show Gist options
  • Select an option

  • Save j10sanders/80d0df1ad24a41f6c2ca to your computer and use it in GitHub Desktop.

Select an option

Save j10sanders/80d0df1ad24a41f6c2ca to your computer and use it in GitHub Desktop.
__author__ = 'Jonathan'
class Musician(object):
def __init__(self, sounds):
self.sounds = sounds
def solo(self, length):
for i in range(length):
print(self.sounds[i % len(self.sounds)],)
print("")
class Bassist(Musician): # The Musician class is the parent of the Bassist class
def __init__(self):
# Call the __init__ method of the parent class
super(Bassist, self).__init__(["Twang", "Thrumb", "Bling"])
class Guitarist(Musician):
def __init__(self):
# Call the __init__ method of the parent class
super(Guitarist, self).__init__(["Boink", "Bow", "Boom"])
def tune(self):
print("Be with you in a moment")
print("Twoning, sproing, splang")
class Drummer(Musician):
def __init__(self):
# Call the __init__ method of the parent class
super(Drummer, self).__init__(["Tss", "Ding", "Dong"])
def count_combust(self):
print("One, two, three, four")
print("Combust!")
class Band(object):
def __init__(self, hire):
self.hire = hire
def hire_person(self):
if self.hire == Bassist:
hire = Bassist()
one = hire
print(one.solo(10))
elif self.hire == Guitarist:
hire = Guitarist()
one = hire
print(one.solo(10))
else:
hire = Guitarist()
print(hire.tune())
def main():
nigel = Guitarist()
nigel.solo(6)
nigel.tune()
print("Nigel does", nigel.sounds)
joe = Drummer()
joe.solo(4)
joe.count_combust()
pythonic = Band(Guitarist)
pythonic.hire_person()
if __name__ == '__main__':
main()
@barraponto
Copy link

You're passing a class when you're creating the band, like pythonic = Band(Guitarist). the problem with that is that your band will only be able to hire Guitarists! Also, it doesn't really hire them, it just invites them over for a jam, they play and then they're gone! What if Band had a property where you could append more band members?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment