Just making sure that you know!

This has to be one of the few questions you would hear in an interview. But there obviously you'll have only 5 minutes to prove that you know this.

I’m here to make you sure that you've got this!

SOLID is one of the most important acronyms in the world of Object-Oriented Programming.

Why should you care about SOLID programming?

First of all, you have to realize you are not going to be forever where you are. If we use standards and well-known architectures, we can be sure that our code will be easy to maintain by other developers that come after us, and I’m sure you wouldn’t want to deal with the task of fixing a code that didn’t apply any known methodology as it would be very hard to understand it.

Let's jump right in.

I know you’ve been waiting!

What does SOLID stand for?

S — Single Responsibility Principle. O — Open Closed Principle. L — Liskov Substitution Principle. I — Interface Segregation Principle. D — Dependency Inversion Principle.

Single Responsibility Principle:

A class should have only one reason to change.

As its name suggests, this principle implies that a class/module must do only one thing, have only one responsibility. If our class does more than one thing, then we should split the functionalities into different classes.

In the context of the Single Responsibility Principle (SRP), we define responsibility as “a reason for change”. If you can think of more than one motive for changing a class, then that class has more than one responsibility.

Example. Let's suppose we have a Phone which has different functions like Calling, Messaging, Calculator, FlashLight, etc. Now when we define this class, we’ll have one Phone.java file, which will contain all the functions. Now, this class violates the SRP Principle as this class has been assigned multiple responsibilities. To make the class stop violating the principle, we should define the responsibilities in separate classes like Calling.java, Messaging.java, Calculator.java, thus making short components/classes and dividing the responsibilities.

Android specific Example. The method onBindViewHolder of the RecyclerView widget. The role of the onBindViewHolder is to map a list item to a view. There should be no logic in this method. So if there's any code that relates to the logic, you should probably remove from there.