C C T B H P N

Design Concept #2b - Single Responsibility Prinicple

Software systems often become quite large and complex. In order to understand and manage these large systems it is important for each part to focus on implementing a single responsibility. This is important for components at all levels, e.g., functions, classes, packages, modules, and programs. Using the Single Responsibility Principle:
So how do we build complex systems out of components that each have a single responsibility? We'll demonstrate with an example. The class diagram below represents a parser used for code analysis in course projects in Software Modeling & Analysis and Object Oriented Design.
The parser is composed of four modules: Executive, Display, Parser, and Scanner. Their responsibilities are: Each module contains a small number of classes, each with a single responsibility. The Scanner contains classes: The Parser contains classes:

Conclusions for Single Responsibility Principle:

In the parser example we've seen that: These responsibilities are each described in a sentence or two and are relatively easy to understand. The consequence of using SRP in the parser design is that a quite complex processing implementation has been broken down into simple to understand parts. The result is that the amount of time to understand parser well enough to use it is surprisingly short and the code is much easier to maintain that it would otherwise have been. The Single Responsiblity Principle is the most important of all of the design principles we'll discuss in Software Modeling & Analysis and in Object Oriented Design.