Python OOP console app
Python simple app with OOP model
# animal.py
class Animal:
def __init__(self, name, species):
self.name = name
self.species = species
def make_sound(self):
pass # Abstract method
# dog.py
from animal import Animal
class Dog(Animal):
def __init__(self, name, breed):
super().__init__(name, species="Dog")
self.breed = breed
def make_sound(self):
return "Woof!"
# cat.py
from animal import Animal
class Cat(Animal):
def __init__(self, name, color):
super().__init__(name, species="Cat")
self.color = color
def make_sound(self):
return "Meow!"
# app.py
from dog import Dog
from cat import Cat
def main():
dog1 = Dog("Buddy", "Labrador")
cat1 = Cat("Whiskers", "Orange")
print(f"{dog1.name} the {dog1.species} says: {dog1.make_sound()}")
print(f"{cat1.name} the {cat1.species} says: {cat1.make_sound()}")
if __name__ == "__main__":
main()