Picture this: you are on the engineering team behind the result-checking feature of a mock test platform, something like PrepSir, the exam-prep platform many of you use every day for daily practice questions. Everything works fine for months. Then one quiet Tuesday, a developer adds a new rule for negative marking, and two completely unrelated things break: the score-report emails stop going out, and the rank list freezes for everyone. Nobody touched the email code. Nobody touched the ranking code. So what actually went wrong?
This kind of breakage has a name in software engineering, and once you understand it, you will start noticing it everywhere, from the apps you use daily to the codebases hiring managers ask about in interviews. The fix is a set of five rules called the SOLID principles, and today we are going to go through all five, in plain language, with code simple enough that you do not need prior programming experience to follow the idea.
Why Software Gets Messier the Bigger It Grows
When a program is small, you can hold the whole thing in your head. A hundred lines of code is like a one-room house: you can see every wall from where you stand. But real software, the kind that runs a banking app or an exam platform used by lakhs of students, can run into millions of lines, built by hundreds of people over many years.
The trouble is that most code does not start messy. It gets messy one small shortcut at a time. A function that was meant to do one thing quietly grows a second job, then a third. A class built for one exam category gets an extra rule bolted on for every new category that comes along. None of these shortcuts look dangerous on the day someone writes them. The danger shows up years later, when changing one small thing breaks three things nobody expected, exactly like our email-and-rank-list mystery above.
Discipline is not willpower or robot-like routine. Learn how the brain builds habits, why boredom appears, and how to keep a routine that keeps working.
·10 min read
Five Rules That Keep Code From Rotting
In the early 2000s, Robert C. Martin, an American software engineer and author widely known by his nickname "Uncle Bob," who has written and taught about software design since the 1990s, gathered five design ideas that experienced programmers had already been using somewhat informally. He arranged them so their first letters spelled a word that was easy to remember: SOLID. You can read more about Robert C. Martin's work and the SOLID design principles on Wikipedia.
SOLID is not a feature of any particular programming language. It is a set of habits, a way of shaping your code so that adding a new feature feels like adding a new room to a house rather than knocking down a wall and hoping the roof does not fall in. We will use Python, a beginner-friendly language, for every example, and walk through what each piece of code is doing in plain English before and after.
Python, the beginner-friendly language used for every code example in this article. Image: Wikimedia Commons, Python Software Foundation
S: Give Every Class One Job (Single Responsibility Principle)
Here is the class that likely caused our mystery bug. It is called ResultProcessor, and if you look closely, it is quietly doing three unrelated jobs at once: calculating a score, formatting an email, and saving data.
class ResultProcessor:
def calculate_score(self, answers, answer_key):
# works out how many answers were correct
correct = sum(1 for a, k in zip(answers, answer_key) if a == k)
return correct
def send_result_email(self, student_email, score):
# builds and "sends" an email to the student
print(f"Emailing {student_email}: Your score is {score}")
def save_to_database(self, student_id, score):
# pretends to save the score to storage
print(f"Saving score {score} for student {student_id}")
This looks harmless, but think about what happens the day someone needs to change how scores are calculated, say, to add negative marking. They open ResultProcessor and edit calculate_score, and because everything lives in one class, a careless change or a shared piece of data can quietly affect send_result_email and save_to_database too, even though nobody meant to touch them. That is exactly how one change breaks two unrelated features.
The Single Responsibility Principle says a class should have only one reason to change. Split the jobs apart:
class ScoreCalculator:
def calculate(self, answers, answer_key):
correct = sum(1 for a, k in zip(answers, answer_key) if a == k)
return correct
class EmailNotifier:
def send_result_email(self, student_email, score):
print(f"Emailing {student_email}: Your score is {score}")
class ResultRepository:
def save(self, student_id, score):
print(f"Saving score {score} for student {student_id}")
Now, changing how marks are calculated only ever touches ScoreCalculator. Think of it like a tiffin service where one person cooks, one person packs, and one person delivers, rather than one person trying to do all three at once while the queue of hungry customers grows.
O: Add New Behaviour Without Rewriting Old Code (Open/Closed Principle)
Now imagine the platform needs to apply different fee concessions for different categories of students. A common first attempt looks like this:
def get_fee(student_category, base_fee):
if student_category == "general":
return base_fee
elif student_category == "sc_st":
return base_fee * 0.5
elif student_category == "ews":
return base_fee * 0.75
# every new category means opening this function again
This function works today, but every time a new category is introduced, somebody has to reopen this exact function and add another rule, right next to logic that has nothing to do with the new category, risking a mistake in code that was already tested and working.
Good software design lets you snap on new pieces, like Lego bricks, without taking the existing structure apart. Image: Wikimedia Commons, CC BY 2.0
The Open/Closed Principle says code should be open for extension but closed for modification: you should be able to add new behaviour without editing code that already works. Small, swappable classes solve this:
class GeneralFee:
def calculate(self, base_fee):
return base_fee
class SCSTFee:
def calculate(self, base_fee):
return base_fee * 0.5
class EWSFee:
def calculate(self, base_fee):
return base_fee * 0.75
def get_fee(fee_rule, base_fee):
return fee_rule.calculate(base_fee)
A brand-new category is now a brand-new class sitting quietly beside the others, never touching code that already works, just like adding one more Lego brick to a model without taking the existing structure apart.
L: A Replacement Should Never Surprise You (Liskov Substitution Principle)
This rule is named after Barbara Liskov, a computer scientist who first described the idea in 1987, and it is easiest to understand with birds rather than code. If you tell a child "a bird is an animal that flies," and then show them a penguin and say "this is a bird too," the child feels cheated, because a penguin cannot fly. The category "bird" made a promise that penguins break.
Programmers make the exact same mistake:
class Bird:
def fly(self):
print("Flying high!")
class Penguin(Bird):
def fly(self):
raise Exception("Penguins can't fly!")
Anywhere in the program that expects a Bird and calls fly() on it, handing it a Penguin instead will crash the program, even though a penguin is technically "a kind of" bird. The Liskov Substitution Principle says a subtype must be usable anywhere its parent type is expected, without surprises. The honest fix is to stop pretending all birds fly:
class Bird:
def eat(self):
print("Eating...")
class FlyingBird(Bird):
def fly(self):
print("Flying high!")
class Penguin(Bird):
def swim(self):
print("Swimming fast!")
Now nothing promises a penguin can fly, so nothing gets surprised later. This exact mistake shows up constantly in real systems, for example when a "refundable payment" category quietly includes a payment method that, in practice, can never actually be refunded instantly.
I: Do Not Force Anyone to Implement Buttons They Will Never Use (Interface Segregation Principle)
Imagine a software contract, called an interface in programming, that says "every printer in our system must support print, scan, and fax." That sounds reasonable until you add a cheap, print-only printer to the system:
BasicPrinter is being forced to promise features it cannot deliver, just to satisfy a contract that was written with a fancier machine in mind. The Interface Segregation Principle says no class should be forced to depend on methods it never uses. Breaking the one big contract into smaller, focused ones fixes it:
class Printable:
def print_doc(self):
print("Printing...")
class Scannable:
def scan_doc(self):
print("Scanning...")
class BasicPrinter(Printable):
pass
class AllInOnePrinter(Printable, Scannable):
pass
Each class now only signs up for what it can actually do. It is the same reason a good exam-prep app shows a Tier 1 aspirant only the Tier 1 syllabus, instead of forcing them to scroll past Tier 2 interview tips they cannot use yet.
D: Depend on the Idea, Not the Exact Tool (Dependency Inversion Principle)
Finally, look at how our earlier EmailNotifier might get used inside a bigger reminder system:
class ReminderService:
def __init__(self):
self.notifier = EmailNotifier() # hard-wired to one exact tool
def remind(self, student_email, message):
self.notifier.send_result_email(student_email, message)
ReminderService is welded directly to EmailNotifier. The day the platform wants to send reminders by SMS instead of, or alongside, email, somebody has to tear open ReminderService itself to change it, even though "reminding a student" has nothing to do with the exact delivery method.
The Dependency Inversion Principle says high-level logic should depend on an abstraction, a general idea of "something that can notify," not on one specific tool. In practice:
Now ReminderService works with any Notifier at all, whether it sends email, SMS, or something invented five years from now, without a single line inside ReminderService ever changing. This is exactly like a plug point in your home: the socket does not care whether you plug in a phone charger or a table lamp, as long as the plug fits the standard shape.
Back to the Mystery Bug
Remember the broken emails and the frozen rank list from the start of this article? Now you can see exactly how that kind of chaos happens. A single bloated class handling scoring, emailing, and saving violates the Single Responsibility Principle. A tangle of rules for every new exam category violates the Open/Closed Principle. A notification system hard-wired to one exact tool violates Dependency Inversion. Each violation on its own seems small, but stacked together across a real codebase, they turn one Tuesday afternoon change into three unrelated features catching fire at once.
Why This Is Worth Learning Now, Not Later
You do not need years of experience to start writing SOLID code; you need the habit of asking, before you write a class, "does this do one job, and can someone extend it without cracking it open?" That single question will make your code easier to test, easier to debug at 2 a.m., and easier for a teammate to read six months later. It is also one of the most common topics in software and system-design interview rounds for IT roles, in both private companies and public-sector banks and PSUs, so the habit pays off twice: once in the quality of what you build, and once in how confidently you can explain your design choices. For the exact interview pattern and eligibility details of any specific exam, always confirm the latest information on the organisation's own official notification before you start preparing.