Bhodi's Tutoring - Dead by Daylight Edition

Example 3: Object Oriented Programming (OOP)

OOP Principles: Inheritance, Encapsulation, Polymorphism

This example demonstrates OOP principles using a Dead by Daylight theme. We have a base Character class, and two subclasses: Survivor and Killer. Each subclass overrides the action method to show polymorphism.

# --- OOP Example: Dead by Daylight Characters ---
class Character:
    def __init__(self, name):
        self.name = name  # Encapsulation: attribute is part of the object
    def action(self):
        print(f"{self.name} does something mysterious...")

class Survivor(Character):  # Inheritance
    def action(self):       # Polymorphism (method override)
        print(f"{self.name} repairs a generator and hides from the Killer!")

class Killer(Character):    # Inheritance
    def action(self):       # Polymorphism (method override)
        print(f"{self.name} hunts for Survivors!")

# Example usage:
characters = [
    Survivor("Meg"),
    Killer("The Trapper"),
    Survivor("Dwight")
]
for c in characters:
    c.action()
← Back to Bhodi's Tutoring Home