design-patterns/behavioral/chain_responsibility/concrete_handlers.py
Ruidy 912226c9a9
Chain of Responsibility (#15)
* chore: create behavioral design patterns package

* doc: add chain of responsibility documentation

* doc: add behavioral package table of content

* doc: edit general doc

* add code example

Co-authored-by: Ruidy <r.nemausat@empfohlen.de>
2020-09-30 14:12:08 +02:00

28 lines
858 B
Python

"""
All Concrete Handlers either handle a request or pass it to the next handler in
the chain.
"""
from typing import Optional, Any
from behavioral.chain_responsibility.abstract_handler import AbstractHandler
class MonkeyHandler(AbstractHandler):
def handle(self, request: Any) -> Optional[str]:
if request == 'Banana':
return f"Monkey: I'll eat the {request}"
return super().handle(request)
class SquirrelHandler(AbstractHandler):
def handle(self, request: Any) -> Optional[str]:
if request == 'Nut':
return f"Squirrel: I'll eat the {request}"
return super().handle(request)
class DogHandler(AbstractHandler):
def handle(self, request: Any) -> Optional[str]:
if request == 'MeatBall':
return f"Dog: I'll eat the {request}"
return super().handle(request)