liveBook · Manning

Delegation principle

As explained in Object-Oriented Software Design in C++

A design principle in which one class assigns work to another class whose cohesive responsibilities make it more suitable to perform that work.

Move work from a requester class into a more suitable, cohesive delegate. The requester asks the delegate to perform the work without depending on its implementation. section 2.3.2

Delegation improves the design by:

  • Keeping attribute matching inside Attributes, where that responsibility fits better. section 2.3.2
  • Reducing Catalogue's knowledge of book attributes and limiting change leaks. section 2.3.2
  • Supporting loose coupling among Catalogue, Book, and Attributes. section 2.3.2

Catalogue delegates matching

Catalogue::find() obtains each Book object's Attributes object and calls is_match(target_attrs). Catalogue coordinates the search while Attributes decides whether attributes match.

How Object-Oriented Software Design in C++ covers it

How deep it goes
Defines requester–delegate roles and demonstrates one C++ search refactoring, stopping short of broader implementation guidance.
Examples
Uses a book Catalogue, Book objects, Attributes objects, and attribute-based searches as concrete delegation examples.
What you can do after
Apply it via cohesive classes that request specialized work without depending on the delegate's implementation.
How it connects
Connects delegation to the Single Responsibility Principle and Principle of Least Knowledge through cohesion and reduced dependencies.

Also explained in

Compare how 2 books explain delegation principle →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Object-Oriented Software Design in C++. The section links point to the parts of the book it draws on.