Skip to content

Instantly share code, notes, and snippets.

@shaunagm
Created November 13, 2017 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaunagm/45657b0e19f3cbeadb036e40d4ce1a8a to your computer and use it in GitHub Desktop.
Save shaunagm/45657b0e19f3cbeadb036e40d4ce1a8a to your computer and use it in GitHub Desktop.
# Subclassing -- not ideal in Django because PythonProgrammer object will have data stored in Programmer
# and Worker since they are concrete, not abstract
class Human(object):
name = "Eve"
Meta:
abstract = True
def get_human_data(self):
return "Name: " + self.name
class Worker(Human):
age_at_first_job = 18
def get_human_data(self):
return "Name: " + self.name + " Age at first job: " + self.age_at_first_job
class Programmer(Worker):
favorite_language = "Go"
def get_human_data(self):
return "Name: " + self.name + " Age at first job: " + self.age_at_first_job + " language: " + self.favorite_language
class PythonProgrammer(Programmer):
job_language = "Python"
def get_human_data(self):
return "Name: " + self.name + " Age at first job: " + self.age_at_first_job + " languages " + self.favorite_language + self.job_language
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment