Creational Patterns

Examples:

Code Example - Factory Pattern

class Animal:
    def speak(self):
        pass

class Dog(Animal):
    def speak(self):
        return "Woof!"

class Cat(Animal):
    def speak(self):
        return "Meow!"

def animal_factory(animal_type):
    if animal_type == "dog":
        return Dog()
    elif animal_type == "cat":
        return Cat()

# Usage
pet = animal_factory("dog")
print(pet.speak())  # Output: Woof!