mirror of
https://github.com/rjNemo/design-patterns
synced 2026-06-11 21:16:40 +00:00
* 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>
28 lines
858 B
Python
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)
|