From the course: Advanced Design Patterns: Design Principles

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Single responsibility principle

Single responsibility principle

- [Instructor] The Single Responsibility Principle is one of the simplest principles. It's also one of the hardest to get right. This principle is all about limiting the impact of change. It says that a class should only have one reason to change. The logic being, for every new responsibility that a class takes on, that's a new opportunity for it to change in the future, which, in general, we want to minimize. Why? Because we want to limit the responsibilities of a class, so that we can mimimize probability of change to that class in the future. One of the reasons this principle is hard to get right, is because it's not a clear-cut guideline. After all, what constitutes responsibility? Should we just design every class to do just one thing? Are multiple responsibilities really going to degenerate into a set of never ending changes just because a class does more than one thing? Well, let's look at an example, borrowed from…

Contents