LLD - Behavioral Design Patterns — Part 1
Given the following code snippet, identify the bug that breaks the Chain of Responsibility pattern:
What is the main issue here?
class Handler:
def __init__(self, successor=None):
self.successor = successor
def handle(self, request):
if self.can_handle(request):
return f"Handled {request}"
else:
return "Not handled"
def can_handle(self, request):
return False
class ConcreteHandler(Handler):
def can_handle(self, request):
return request == 'X'
chain = ConcreteHandler()
print(chain.handle('Y'))What is the main issue here?
