Skip to content

Commit

Permalink
Merge pull request mouredev#4388 from ggilperez/mouredev#9-Python
Browse files Browse the repository at this point in the history
mouredev#9 - Python
  • Loading branch information
Roswell468 authored Jun 17, 2024
2 parents 1ea7923 + e2197ac commit 371f789
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions Roadmap/09 - HERENCIA/python/ggilperez.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Problem 09 inheritance

class Animal:

def speak(self):
raise NotImplementedError()


class Dog(Animal):

def speak(self):
print("Goof Goof")


class Cat(Animal):

def speak(self):
print("Meow!")


dog = Dog()
dog.speak()

cat = Cat()
cat.speak()


# Extra

class Employee:

def __init__(self, identifier, name):
self.id = identifier
self.name = name
self.employees = []

def show_employees(self):
print(f"'{self.name} ({self.id})' employees:")
for employee in self.employees:
print(employee.name)

def add_employee(self, employee):
self.employees.append(employee)


class Manager(Employee):

def __init__(self, identifier, name):
super().__init__(identifier, name)

def current_job(self):
print(f"Manager '{self.name} ({self.id})' in charge of all the projects.")


class ProjectManager(Employee):

def __init__(self, identifier, name, project):
super().__init__(identifier, name)
self.project = project

def current_job(self):
print(f"PM '{self.name} ({self.id})' in charge of '{self.project}' project.")


class Developer(Employee):

def __init__(self, identifier, name, language):
super().__init__(identifier, name)
self.language = language

def current_job(self):
print(f"Developer '{self.name} ({self.id})' programs in '{self.language}'.")

def show_employees(self):
print("Developers can have other employees in charge.")

def add_employee(self, employee):
print("Developers can have other employees in charge.")


manager = Manager(1, "Foo")
pm = ProjectManager(2, "Bar", "Proyectito")
dev = Developer(3, "FB", "Python")

manager.add_employee(pm)
manager.add_employee(dev)
manager.show_employees()
manager.current_job()

pm.current_job()
pm.add_employee(dev)
pm.show_employees()

dev.current_job()
dev.add_employee(pm)
dev.show_employees()

0 comments on commit 371f789

Please sign in to comment.