Singly Responsible

For homework, I read last night the chapter on the Single Responsibility Principle (SRP) from Sandi Metz’s book “Practical Object-Oriented Design in Ruby“.

SRP is the idea that a class should have only one responsibility because they are easy to change and therefore easy to reuse.

If you are a visual person, the picture below will give you an idea:

Single responsibility picture

Think of each individual piece of the swiss knife as a method and each method has a sole behavior. The SRP is about structuring your methods in a way that can be easily changed if you need to. As I am learning about Ruby classes, I can see right away the benefit of this principle. A burdensome piece of code that makes modification difficulty is prone to bugs. If each code defines one object behavior, you also avoid the need for commenting on your methods.

I am eager to learn more about this principle and ways I can implement it. I want to write classes that are classy and singly responsible.

One thought on “Singly Responsible

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s