design patterns refactoring
play

Design Patterns & Refactoring Chain of Responsibility Oliver - PowerPoint PPT Presentation

Design Patterns & Refactoring Chain of Responsibility Oliver Haase HTWG Konstanz Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 1 / 9 Description Classification : Object-based behavioral pattern Purpose : Build a chain of


  1. Design Patterns & Refactoring Chain of Responsibility Oliver Haase HTWG Konstanz Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 1 / 9

  2. Description Classification : Object-based behavioral pattern Purpose : Build a chain of possible receivers of a request. Delegate request along the chain until one receiver handles it. Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 2 / 9

  3. Motivation Imagine a context-sensitive help system for a GUI Each graphical component may (or may not) have associated with it a help text. On, e.g., right mouse click, the most specific help text of the clicked-on component is displayed to the user. aMouseListener aPrintButton aPrintDialog aTopLevelContainer handleHelpReq handleHelpReq handleHelpReq Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 3 / 9

  4. Idea Chain-up potential receivers in descending order from most specific to least specific Upon reques, each receiver can decide to handle it ot to propagate it to its successor. Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 4 / 9

  5. Description Applicability : Use the chain-of-responsibility pattern if several objects could handle a request, and it is unknown at development time which one actually will. the set of possible receivers is to be configured dynamically Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 5 / 9

  6. Structure Client Handler successor + handleRequest () ConcreteHandler1 ConcreteHandler2 + handleRequest() + handleRequest() Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 6 / 9

  7. Consequences Loose Coupling : the chain-of-responsibility pattern decouples the sender of a request from the receiver. No Processing Guarantee : Because each receiver may decide not to handle a request, it might fall off the chain unprocessed. Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 7 / 9

  8. Implementation The successor chain can either use a pre-existing linkage of the receiver objects, or be built separately. Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 8 / 9

  9. Related Patterns Composite : Often, the parent object of a composite is used as the successor object for a chain of responsibility. Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 9 / 9

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend