Chain-of-responsibility pattern: Difference between revisions

Content deleted Content added
Importing Wikidata short description: "Programming pattern"
Line 65:
return topic != NO_HELP_TOPIC;
}
 
virtual void setHandler(HelpHandler*, Topic) {}
virtual void handleHelp() {
std::cout << "HelpHandler::handleHelp\n";
// (optional) implements the successor link.
if (successor != nullptr) {
successor->handleHelp();
}
}
virtual ~HelpHandler() = default;
HelpHandler(const HelpHandler&) = delete; // rule of three
HelpHandler& operator=(const HelpHandler&) = delete;
private:
HelpHandler* successor;
Topic topic;
};
 
class Widget : public HelpHandler {
Line 145 ⟶ 131:
 
button->handleHelp();
}
</syntaxhighlight>
 
The program output is:
 
<syntaxhighlight lang="c++">
Button::handleHelp
</syntaxhighlight>
 
{{wikibooks|Computer Science Design Patterns|Chain of responsibility|Chain-of-responsibility implementations in various languages}}
 
== Implementations ==