0% found this document useful (0 votes)
5 views

Doc1

LAB SOFTWARE DWSIGN AND ARCHITECTURE

Uploaded by

Zurghuna Gul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Doc1

LAB SOFTWARE DWSIGN AND ARCHITECTURE

Uploaded by

Zurghuna Gul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ABBOTTABAD UNIVERSITY OF SCIENCE

AND TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE

COURSE: SDA

LAB:3

Question
 Draw a chain of responsibility pattern for logging system/Handlers.

CHAIN OF RESPONSIBILITY DESIGN PATTERN

The Chain of Responsibility design pattern, is a behavioral design pattern used to pass a request
along a chain of handlers. Each handler in the chain has the opportunity to process the request or
pass it on to the next handler in the chain.

WORKING PATTERN

Here’s a breakdown of how the Chain of Responsibility pattern works:

1. Handler: Defines an interface for handling requests and optionally maintains a reference to
the next handler in the chain.

2. ConcreteHandler: Implements the handling logic and decides whether to process the
request or pass it to the next handler.

3. Client: Constructs the chain of handlers and sends requests to the first handler in the chain.

EXAMPLE:

LOGGING SYSTEM
 The goal is to create a logging system where different types of loggers (Info, Warning, Error)
handle log messages based on their severity levels.
 Each logger in the chain either handles the log message or passes it to the next logger in the
chain.

IMPLEMENTATION
 Step 1: Define the Handler Interface: Create an interface with methods for setting the next
handler and processing requests.
 Step 2: Create Concrete Handlers: Implement the handler interface in multiple classes,
each handling specific requests and passing unhandled requests to the next handler.
 Step 3: Set Up the Chain: Create instances of your handlers and link them together by
setting the next handler for each one.
 Step 4: Send Requests: Use the first handler in the chain to send requests, allowing each
handler to decide whether to process it or pass it along.

STRUCTURE

You might also like