1. The Single Responsibility Principle
(1)Zeist, The Netherlands
The
Single Responsibility principle says that
1:
A class should have one, and only one, reason to change.
There is a strange little jump here, from this principle being about “responsibilities” to the explanation being about “reasons to change”. Well, this is not so strange when you think about it—each responsibility is also a reason to change.
A Class with Too Many Responsibilities
Let’s take a look at a concrete, probably recognizable example of a class that is used to send a confirmation to the email address of a new user (see Listing
1-1 and Figure
1-1). It ...