The Single Responsibility Principle Applied to CSS

Learn how and when to use SRP

Harry Robert talks covered how to build big, scalable front-ends and one of the key factors involved in doing so is sensible and generous use of abstracted classes. One thing that really helps you achieve this is the application of the single responsibility principle, a method used mainly in OO programming. Loosely, the single responsibility principle states that every module or chunk of code (a function etc) should do one job well and one job only. The benefits of this are mainly in the way of maintainability and extensibility.


If we don’t adhere to the SRP then we are likely to end up with code which does more than it should, this means that altering one part of that code could negatively impact a seemingly unrelated part of the same snippet. It also makes our code a lot less flexible in that we find our code is trying to do too much; it is too specific in its job to be portable and reusable. Abstracting chunks of functionality into several responsibilities means we can reuse a lot more of our code and recombine it over and over with other similarly abstracted chunks.

Comments

Single Responsibility Principle to javascript programming

January 23, 2016 by User
Thank you for your post, well done! I also found this video https://youtu.be/bZSdnfARpnY to be very helpful to learn the SRP with a javascript code example.

You must me logged in to write a comment.