The Single-Responsibility Principle

Today is January 01, 2017. Happy and prosperous New Year!!!

As I have mentioned in prior blog entries, among many other activities, I enjoy reading technical books in order to learn, refresh and on occasions question what some may consider common knowledge. One of the books that I am currently reading is “Agile Software Development Principles, Patterns and Development” by Robert C. Martin. So far, I recommend this book to people studying and practicing computer science.

In most cases, with experience things tend to move from black and white to shades of gray. The Agile methodology is one of them. I have learned, read books and articles and practiced Agile for a few decades. As an example, this book is pro Agile. A couple years ago I read the book “Agile! The Good, the Hype and the Ugly” by Bertrand Meyer. As the book cleverly states, Agile has some good things and some not so good. This is just one example of shades of gray. There is no silver bullet as Frederick P. Brooks Jr. wrote in an essay of the same name in its seminal book “The Mythical Man-Month: Essays on Software Engineering” published in 1975 (way before Agile was defined). In the past few decades I have bought at least twice a copy of the book. On several occasions I have purchased copies of the book and handed to customers (project subject domain expert) of projects I have led. Any type of software development methodology has to be adjusted for the type of project (e.g., storage drive, robotic unit, storage server, and business system), the development team and the company. They all have an impact on how software engineering principles and software development methodologies are implemented.

Chapter 8 in the “Agile Software Development” book covers the Single-Responsibility Principle. After reading the chapter, I decided to take a look at Wikipedia.

The single responsibility principle states that every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility. Robert C. Martin expresses the principle as follows:  A class should have only one reason to change.

The term was introduced by Robert C. Martin in an article by the same name as part of his Principles of Object Oriented Design, made popular by his book Agile Software Development, Principles, Patterns, and Practices. Martin described it as being based on the principle of cohesion, as described by Tom DeMarco in his book “Structured Analysis and System Specification”, and Meilir Page-Jones in “The Practical Guide to Structured Systems Design”.

The DeMarco book was first published in 1978. The Martin book was first published in 2003 and the book by Page-Jones was first published in 1980. It seems that the single-responsibility principle (with different names) was introduced in a wide period that dates back to 1978 to 2003.

Now let’s take a look at UNIX which I have worked with to develop several commercial systems for a fortune 100 company. The UNIX philosophy (“Write programs that do one thing and do it well”) was documented by Doug McIlroy in the “The Bell System Technical Journal” in 1978.

[1] Make each program do one thing well. [2]To do a new job, build afresh rather than complicate old programs by adding new “features”. [3] Expect the output of every program to become the input to another, as yet unknown, program. [4] Don’t clutter output with extraneous information. [5] Avoid stringently columnar or binary input formats. [6] Don’t insist on interactive input. [7] Design and build software, even operating systems, to be tried early, ideally within weeks. [8] Don’t hesitate to throw away the clumsy parts and rebuild them. [9] Use tools in preference to unskilled help to lighten a programming task, even if you have to detour to build the tools and expect to throw some of them out after you’ve finished using them.

Seems like Agile, CDP, SCRUM, XP and many other software development methodologies ‘copied’ (or better say stood on the shoulders of giants) most features that were created by Kenneth Thompson and Dennis Ritchie when working at Bell Labs on the UNIX operating system which was first released in 1969.

The Single-Responsibility Principle of Agile described in the Agile Software Development book by Robert Martin is solid, has been used since the 1960s and should always be considered by software architects, designers and developers using most original or modified software development methodologies.

If you have comments or questions regarding this or any other entry in this blog, I would like to hear from you. Please take a couple minutes and send me a message. I will not use your name unless you explicitly let me know.


Follow me on Twitter: @john_canessa


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.