CSE687 - Lecture #1 Design Note

Single Responsibility Principle (SRP)

Revised: 12/9/2009
Home Courses Code Books Handouts Research SWDev WebDev News OtherLinks SiteDesign

CSE681-SWMA CSE687-OOD CSE691-IP CSE775-DO CSE776-DP CSE778-AWP CSE784-SWS

Lecture #1 Lecture #2


Single Responsibility Principle (SRP):

Each class should have only one reason to change.

Each module should be responsible for only a single activity.

Examples:

  1. The tok module, in semi project folder is responsible for extracting tokens from a stream.
  2. tok contains three classes:

Elaboration:


" If a class has more than one responsibility, then the responsibilities become coupled. Changes to one responsibility may impare or inhibit the ability of the class to meet the others. This kind of coupling leads to fragile designs that break in unexpected ways when changed. "
- Robert C. Martin, Agile Software Development, Prentice-Hall