Created
October 1, 2011 10:34
-
-
Save adaptives/1255853 to your computer and use it in GitHub Desktop.
LPTHW Exercise 45
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
## Animal is-a object (yes, sort of confusing) look at the extra credit | |
class Animal(object): | |
pass | |
## is-a Animal | |
class Dog(Animal): | |
def __init__(self, name): | |
## has-a name | |
self.name = name | |
## is-a Animal | |
class Cat(Animal): | |
def __init__(self, name): | |
## has-a name | |
self.name = name | |
## is-a Object | |
class Person(object): | |
def __init__(self, name): | |
## has-a name | |
self.name = name | |
## Person has-a pet of some kind | |
self.pet = None | |
## is-a Person | |
class Employee(Person): | |
def __init__(self, name, salary): | |
## We are calling the constructer of the superclass | |
super(Employee, self).__init__(name) | |
## has-a salary | |
self.salary = salary | |
## is-a Object | |
class Fish(object): | |
pass | |
## is-a Fish | |
class Salmon(Fish): | |
pass | |
## is-a Fish | |
class Halibut(Fish): | |
pass | |
## rover is-a Dog | |
rover = Dog("Rover") | |
## satan is a Cat | |
satan = Cat("Satan") | |
## mary is a Person | |
mary = Person("Mary") | |
## mary has a pet which is satan | |
mary.pet = satan | |
## frank is a Employee | |
frank = Employee("Frank", 120000) | |
## frank has a pet which is rover | |
frank.pet = rover | |
## flipper is a Fish | |
flipper = Fish() | |
## crouse is a Salmon | |
crouse = Salmon() | |
## harry is a Halibut | |
harry = Halibut() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment