© Matthias Noback 2018
Matthias NobackPrinciples of Package Designhttps://doi.org/10.1007/978-1-4842-4119-6_1

1. The Single Responsibility Principle

Matthias Noback1 
(1)
Zeist, The Netherlands
 
The Single Responsibility principle says that1:

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 ...

Get Principles of Package Design: Creating Reusable Software Components now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.