83 lines
1.5 KiB
Python
83 lines
1.5 KiB
Python
## Animal is-a object (yes, sort of confusing) look at the extra credit
|
|
class Animal(object):
|
|
def something(self):
|
|
print("base")
|
|
|
|
|
|
## Dog is-a Animal
|
|
class Dog(Animal):
|
|
def __init__(self, name):
|
|
## Dog has-a name
|
|
self.name = name
|
|
|
|
|
|
## Cat is-a Animal
|
|
class Cat(Animal):
|
|
def __init__(self, name):
|
|
## Cat has-a name
|
|
self.name = name
|
|
|
|
|
|
## Person is-a object
|
|
class Person(object):
|
|
def __init__(self, name):
|
|
## Person has-a name
|
|
self.name = name
|
|
## Person has-a pet of some kind
|
|
self.pet = None
|
|
|
|
|
|
## Employee is-a person
|
|
class Employee(Person):
|
|
def __init__(self, name, salary):
|
|
## heritage from parents
|
|
super(Employee, self).__init__(name)
|
|
## Employee has-a salary
|
|
self.salary = salary
|
|
|
|
|
|
## Fish is-a object
|
|
class Fish(object):
|
|
def __init__(self):
|
|
print("Base Fish")
|
|
|
|
|
|
## Salmon is-a Fish
|
|
class Salmon(Fish):
|
|
pass
|
|
|
|
|
|
## Halibut is-a Fish
|
|
class Halibut(Fish):
|
|
pass
|
|
|
|
|
|
## rover is-a Dog
|
|
rover = Dog("Rover")
|
|
rover.something()
|
|
## satan is-a Cat
|
|
satan = Cat("Satan")
|
|
|
|
## mary is-a Person
|
|
mary = Person("Mary")
|
|
|
|
## mary's pet is satan
|
|
mary.pet = satan
|
|
print(mary.pet.name)
|
|
|
|
## frank is-a Employee
|
|
frank = Employee("Frank", 120000)
|
|
|
|
## frank's pet is rover
|
|
frank.pet = rover
|
|
print(frank.name)
|
|
print(frank.pet.name)
|
|
print(frank.salary)
|
|
## flipper is-a Fish
|
|
flipper = Fish()
|
|
|
|
## crouse is-a Salmon
|
|
crouse = Salmon()
|
|
|
|
## harry is-a Halibut
|
|
harry = Halibut()
|