O'Reilly logo

Agile Principles, Patterns, and Practices in C# by Robert C. Martin, Micah Martin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8. The Single-Responsibility Principle (SRP)

image

© Jennifer M. Kohnke

None but Buddha himself must take the responsibility of giving out occult secrets . . .

—E. Cobham Brewer 1810–1897, Dictionary of Phrase and Fable (1898)

This principle was described in the work of Tom DeMarco1 and Meilir Page-Jones.2 They called it cohesion, which they defined as the functional relatedness of the elements of a module. In this chapter, we modify that meaning a bit and relate cohesion to the forces that cause a module, or a class, to change.

The Single-Responsibility Principle

A class should have only one reason to change.

Consider the bowling game from Chapter ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required