HackIndia Logo
HackathonsNewsSkillsGrowth
HackIndia LogoContact: +91 9910125804

General

  • Companies
  • Colleges
  • Board of Advisors
  • Brand Ambassadors
  • FAQ
  • Contact
  • Report a Bug

Hackathons

  • Upcoming Hackathons
  • Judges
  • Mentors
  • Partners
  • Participating Colleges

Resources

  • About Us
  • Branding
  • Latest News
  • Growth
  • Skills
  • Ecosystem
  • Forum
  • Ideas
  • Prompt Optimizer
  • How to earn XP

© 2026 HackIndia. All rights reserved.

Privacy PolicyTerms of ServiceCode of ConductSitemap

Build 2.139 · 09 Nov 2026, 10:59 UTC

    HackIndia
    HackathonsNewsInternshipsSkillsGrowth
    Working towardsOOP
    0%

    0 of 9 steps done · +100 XP · +50 SHARP when it is yours

    1. 1Objects that solve features4 min · +10 XP · +5 SHARP
    2. 2Classes, objects, and state4 min · +10 XP · +5 SHARP
    3. 3Encapsulation without overengineering4 min · +10 XP · +5 SHARP
    4. 4Composition before inheritance4 min · +10 XP · +5 SHARP
    5. 5Polymorphism through interfaces5 min · +10 XP · +5 SHARP
    6. 6SOLID in plain words4 min · +10 XP · +5 SHARP
    7. 7Build and submit your repo5 min · +10 XP · +5 SHARP
    8. The check10 questions, 7 to pass · +10 SHARP
    9. Hand in the taskA project that uses the skill
    10. Skill and certificate+100 XP · +50 SHARP
    Lesson 6 of 7 4 min

    OOP

    SOLID in plain words

    • +10 XP for this lesson
    • +100 XP when the skill is proved
    • 3 learning it right now
    In 30 seconds
    • Use SOLID as five checks for cleaner OOP choices.
    • Spot when a class, interface, or dependency is doing too much.
    Make one small refactor that improves your feature repo.
    Key point

    One idea

    SOLID is not a rulebook to impress seniors. It is a set of checks that helps your feature stay easy to change without breaking everything else.

    Use it after you have working code. First ship the feature. Then clean the design where change is likely.

    The five checks

    S means Single Responsibility. A class should have one main reason to change. For example, Order should not also send WhatsApp messages and write invoices.

    O means Open/Closed. Add a new behaviour by adding a new class when possible, not by editing one big if-else block every time.

    The next three

    L means Liskov Substitution. If code expects a PaymentMethod, any UpiPayment or CardPayment should work without surprise errors.

    I means Interface Segregation. Do not force a class to implement methods it does not need. D means Dependency Inversion. High-level code should depend on interfaces, not hard-coded concrete classes.

    Example

    Small payment example

    Here is a simple Dependency Inversion and Open/Closed example. Checkout uses the PaymentMethod interface. Adding NetBankingPayment later will not require changing Checkout.

    interface PaymentMethod {
      boolean pay(int amountInRupees);
    }
    
    class UpiPayment implements PaymentMethod {
      public boolean pay(int amountInRupees) {
        System.out.println("Paid ₹" + amountInRupees + " using UPI");
        return true;
      }
    }
    
    class Checkout {
      private final PaymentMethod paymentMethod;
    
      Checkout(PaymentMethod paymentMethod) {
        this.paymentMethod = paymentMethod;
      }
    
      boolean placeOrder(int amountInRupees) {
        return paymentMethod.pay(amountInRupees);
      }
    }
    
    class Main {
      public static void main(String[] args) {
        Checkout checkout = new Checkout(new UpiPayment());
        checkout.placeOrder(499);
      }
    }
    Common mistake

    Do not over-SOLID

    Beginners sometimes create ten interfaces for a two-class feature. That makes the repo harder to read, not better.

    Use SOLID to remove pain. If there is only one implementation and no likely change, a direct class may be fine.

    Tip

    Use AI carefully

    Ask an AI tool to review your object model using SOLID. Then check the advice yourself. AI often suggests extra abstractions you do not need.

    A useful prompt: Review these classes for SOLID issues. Suggest only changes that make the feature easier to test or extend. Avoid adding patterns unless needed.

    Your to-do

    SOLID review pass

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    Your to-do

    Do this now

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    Quick check

    0 of 2 right
    1.Your Checkout class has a long if-else for UPI, card, and wallet payments. Which SOLID idea helps you add new payment types cleanly?
    2.A Report class calculates marks, formats a PDF, and emails it. What is the clearest SOLID problem?

    Answer the quick check to finish this lesson.

    ← Lesson 5Skip to lesson 7 →
    Working towards
    OOP +100 XP

    0 of 7 lessons done · proved by a project that uses the skill

    See the track