· · ─ ·✶· ─ · ·

Let’s start right at the root. Why do software engineers care about SOLID principles?

Simply, these principles help us design object oriented software systems that are:

Scalable

Scalable

Understandable

Understandable

Flexible

Flexible

And all of the above make our job as software engineers a lot nicer because the enterprise applications that we work on become more maintainable.

Repeat after me - “We love maintainablity in our software systems”.

First up is,

SRP

Lets say, we have a UserService which creates a user. Currently it does 3 things, all in a single method.

SRP2

Now anytime there’s a change in one feature, the class needs to be updated. Why is this bad? We need to unnecessarily test the other 2 features even if a change was made in a single feature. Of course, this toy scenario doesn’t look all too bad. But scale this up and we have a class doing many different complex things. Its the kind of class no developer wants to touch.

Refactor: We split the features and put them in their own class. The UserService can just have references to these feature classes and invoke the features as required.

SRP3

· · ─ ·✶· ─ · ·