94 lines
2.4 KiB
Python
94 lines
2.4 KiB
Python
## Animal is parents
|
|
## Animal is-a object (yes, sort of confusing) look at the extra credit
|
|
class Animal(object):
|
|
pass
|
|
|
|
## Animal is parents and Dog is child
|
|
## Dog is-a Animal and has-a __init__ that takes self and name parameters
|
|
class Dog(Animal):
|
|
|
|
def __init__(self, name):
|
|
## Dos has-a name
|
|
self.name = name
|
|
|
|
## Animal is parents and Cat is child
|
|
## Cat is-a Animal and has-a __init__ that takes self and name parameters
|
|
class Cat(Animal):
|
|
|
|
def __init__(self, name):
|
|
## Cat has-a name
|
|
self.name = name
|
|
|
|
## Person is parents
|
|
## Person is-a object and has-a __init__ that takes self and name parameters
|
|
class Person(object):
|
|
|
|
def __init__(self, name):
|
|
## Person has-a name
|
|
self.name = name
|
|
|
|
## Person has-a pet of some kind
|
|
self.pet = None
|
|
|
|
## Persion is parents and Employee is child
|
|
## Employee is-a Person and has-a __init__ that takes self and name parameters
|
|
class Employee(Person):
|
|
|
|
def __init__(self, name, salary):
|
|
## ?? hmm what is this strange magic?
|
|
## From super, get the __init__ function, and call it with parameters self, name
|
|
super(Employee, self).__init__(name)
|
|
## Employee has-a salary
|
|
self.salary = salary
|
|
|
|
## Fish is parents
|
|
## Fish is-a object
|
|
class Fish(object):
|
|
pass
|
|
|
|
## Fish is parents and Salmon is child
|
|
## Salmon is-a Fish
|
|
class Salmon(Fish):
|
|
pass
|
|
|
|
## Fish is parents and Halibut is child
|
|
## Halibut is-a Fish
|
|
class Halibut(Fish):
|
|
pass
|
|
|
|
|
|
## Set rover to an instance of class Dog
|
|
## rover is-a Dog that has-a name is-a Rover
|
|
rover = Dog("Rover")
|
|
|
|
## Set satan to an instance of class Cat
|
|
## stan is-a cat that has-a name is-a Satan
|
|
satan = Cat("Satan")
|
|
|
|
## Set mary to an instance of class Person
|
|
## mary is-a Person that has-a name is-a Mary
|
|
mary = Person("Mary")
|
|
|
|
## From mary, get the pet attribute, and set it to satan
|
|
## mary's pet is-a cat that has-a name that is-a Satan
|
|
mary.pet = satan
|
|
|
|
## Set frank to an instance of class Employee
|
|
## frank is-a Employee and salary is-a 120000
|
|
frank = Employee("Frank", 120000)
|
|
|
|
## From frank, get the pet attribute, and set it to rover
|
|
## frank's pet is-a dog that has-a name that is-a Rover
|
|
frank.pet = rover
|
|
|
|
## Set flipper to an instance of class Fish
|
|
## flipper is-a Fish
|
|
flipper = Fish()
|
|
|
|
## Set crouse to an instance of class Salmon
|
|
## crouse is-a Salmon
|
|
crouse = Salmon()
|
|
|
|
## Set harry to an instance of class Halibut
|
|
## harry is-a Halibut
|
|
harry = Halibut()
|