liveBook · Manning

Cohesive class

A class whose methods and instance variables collectively serve one closely related primary responsibility.

How 2 Manning books explain it

Software Design for Python Programmers

A cohesive class is a class whose methods and instance variables collectively serve one closely related primary responsibility.

How it is used
Separates class responsibilities so operations, maintenance, and cleaning can evolve without one overloaded class.
How deep it goes
Defines cohesion and demonstrates responsibility separation through Book/Catalogue and Automobile refactorings, without descending into formal metrics.
Examples
Uses Book and Catalogue classes, case-insensitive catalogue searches, and Automobile, Garage, and CarWash refactorings.
What you can do after
Evaluate class boundaries and refactor mixed responsibilities into smaller classes with one primary responsibility.

Read how Software Design for Python Programmers explains cohesive class →

Object-Oriented Software Design in C++

A class whose members collectively serve one clear primary responsibility.

How it is used
Uses single responsibility to guide class design during iterative application development.
How deep it goes
Defines cohesion and demonstrates refactoring responsibilities, stopping short of implementation internals.
Examples
Uses Book and Catalogue, then contrasts AutomobileApp with Automobile, Garage, and CarWash.
What you can do after
Apply the Single Responsibility Principle to split classes with unrelated state and behavior.

Read how Object-Oriented Software Design in C++ explains cohesive class →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.