FirstHack Learn
Log in Sign up free
Lessons in this course 0/6 All courses Object-Oriented Programming

CSE

Progress0 / 6 lessons
  1. 1. What a class models, and why OOP was invented
  2. 2. Encapsulation, and why getters exist
  3. 3. Inheritance, and when NOT to use it
  4. 4. Polymorphism, with a runnable example
  5. 5. Abstraction: interfaces versus abstract classes
  6. 6. The SOLID principles in plain English

Courses › Object-Oriented Programming

The SOLID principles in plain English

Five design rules, each with the smell it fixes and a short Java example.

14 min read · Lesson 6 of 6 · Pro

Why these five

SOLID is five guidelines for arranging classes so that changing one thing does not force you to change ten others. They are not laws. They are named descriptions of mistakes people kept making.

S — Single Responsibility Principle

A class should have one reason to change.

A class that reads a CSV file, calculates marks and prints a report card has three reasons to change: a new file format, a new grading rule, a new report layout. Three unrelated teams edit the same file and break each other's work.

Split it: a MarksReader, a GradeCalculator, a ReportPrinter. Each has one reason to change.

The rest of this lesson is Pro

The free lessons of Object-Oriented Programming finish what they start — read those first if you have not. This one goes further, and it is part of the paid half.

A pass opens the paid lessons of every course, the mock test papers and the company-wise series. It ends on its own date; nothing renews by itself.

Get a pass — from ₹29 for 7 days

Already bought one? Log in.