Hitesh Sahu
Hitesh SahuHitesh Sahu
  1. Home
  2. β€Ί
  3. posts
  4. β€Ί
  5. …

  6. β€Ί
  7. 2 Priciple

Loading ⏳
Fetching content, this won’t take long…


πŸ’‘ Did you know?

🍌 Bananas are berries, but strawberries are not.

πŸͺ This website uses cookies

No personal data is stored on our servers however third party tools Google Analytics cookies to measure traffic and improve your website experience. Learn more

Loading ⏳
Fetching content, this won’t take long…


πŸ’‘ Did you know?

πŸ™ Octopuses have three hearts and blue blood.
Programming

    AI-AgenticAI

    AI-DeepLearning

    AI-GenAI

    AI-Infrastructure

    AI-Machine-Learning

    AI-Math

    AWS

    Azure

    Hobbies

    kubernetes

    Management

    Programming
    • πŸ“˜ Data Structures, Algorithms & DBMS

    • πŸ’» Principles of Programming πŸ“–

    • βš™οΈ Backend & DevOps πŸ“–

    • πŸ§ͺ Testing πŸ“–

    • πŸŒ€ Agile Methodology πŸ“–

    • πŸ› οΈ Backend - Microservices πŸ“–

    • Programming Index


    Terraform

    Z_Appendix

    0-root

Cover Image for πŸ’» Principles of Programming πŸ“–
Programming

πŸ’» Principles of Programming πŸ“–

A complete guide to programming principles including SOLID, DRY, KISS, YAGNI, Cohesion, and Coupling. Learn best practices for writing clean, maintainable, and scalable code.

Programming
Software Development
SOLID
DRY
KISS
YAGNI
← Previous

πŸ“˜ Data Structures, Algorithms & DBMS

Next β†’

βš™οΈ Backend & DevOps πŸ“–

πŸ’» Software Engineering Principles Cheat Sheet

Principle Emoji Description Key Idea
S: Single Responsibility (SRP) πŸ“ Each class/module should have one responsibility Only one reason to change
O: Open–Closed (OCP) πŸ› οΈ Open for extension, closed for modification Extend without altering existing code
L: Liskov Substitution (LSP) πŸ”„ Subtypes must replace base types without breaking program Substitutability
I: Interface Segregation (ISP) 🧩 Many small client-specific interfaces > one large interface Don’t force unused methods
D: Dependency Inversion (DIP) πŸ”Œ Depend on abstractions, not concretions Inject dependencies for flexibility
DRY: Don’t Repeat Yourself πŸ” Single authoritative representation for every piece of knowledge Avoid duplicated logic
KISS: Keep It Simple, Stupid ✨ Code should be simple and clear Human-readable & easy to maintain
YAGNI: You Aren’t Gonna Need It 🚫 Implement features only when necessary Avoid premature coding

SOLID Principal

-- Robert C. Martin

S: The Single-responsibility principle:

"There should never be more than one reason for a class to change."

Every class should have only one responsibility.

  • Separate UserService and NotificationService rather than combining responsibilities.

O: The Open–closed principle:

"Software entities ... should be open for extension, but closed for modification."

Add new capabilites without breaking original feature

Examples

  • Inheritance Instead of modifying a class declare a new class that inherits the features of the original class and adds new features.
  • Polymorphism: Add new methods in subtypes to extend capabilities.
  • Framework/Lib: Extend to add new capabilites without breaking original feature

L: The Liskov substitution principle:

""Objects of a superclass should be replaceable with objects of a subclass without affecting correctness."."

if S is a subtype of T ( S<:T), then objects of type T may be replaced/substituted with objects of type S without altering any of the desirable properties of the program (correctness, task performed, etc.).

Example

  • ArrayList replace List
  • HR replace Employee
  • `Mock Object replace concrete implementation of Interface

I: The Interface segregation principle:

"Many client-specific interfaces are better than one general-purpose interface."

Dont force super type method upon subtype Example:

  • Autopilot of Vehicle dont work on Train (No left right)

D: The Dependency inversion principle:

"Depend upon abstractions, not concretions"

  • Allow injecting object so that we can test functionality of class

DRY (Don't Repeat Yourself)

"Every piece of knowledge must have a single, unambiguous, authoritative representation within a system".

-- Andy Hunt and Dave Thomas(The Pragmatic Programmer).

DRY Solved WET Problem

  • We enjoy Typing
  • Write every time
  • We enjoy typing
  • Waste everyone's time

Writing the same code/logic again and again for different places/use cases become difficult to manage. If the logic changes, then we have to make changes in all the places where we have written the code, thereby wasting everyone's time.

Example

  • Helper class in enterprise libraries

Advantages

  • Convert code to reusable knowledge/ component/ method & use it in all other places.
  • Easy to maintain, and also reduces the chances of bugs.

Disadvantages:

  • Unnecessary coupling
  • Less flexibility
  • Unnecessary complexity

KISS (Keep It Simple, Stupid)

keep the code simple and clear, making it easy to understand.

-- Andy Hunt and Dave Thomas(The Pragmatic Programmer).

  • Human readable & less spaghetti code
  • Can test simple methods
  • Break down huge block of code

YAGNI (You aren't gonna need it)

programmer should not add functionality until deemed necessary.

--Extreme programming(XP) Principal

  • Always implement things when you actually need them, never when you just foresee that you need them.

Cohesion

*β€œthe code that changes together, stays together.”

  • High Cohesion ensures each unit provides a set of related capabilities and makes the tests of those capabilities easier to maintain.

Coupling

Low Coupling allows each unit to be effectively tested in isolation.

Hitesh Sahu
Written by Hitesh Sahu, a passionate developer and blogger.

Fri Feb 20 2026

Share This on

← Previous

πŸ“˜ Data Structures, Algorithms & DBMS

Next β†’

βš™οΈ Backend & DevOps πŸ“–

Programming/2-Priciple
Let's work together
+49 176-2019-2523
hiteshkrsahu@gmail.com
WhatsApp
Skype
Munich πŸ₯¨, Germany πŸ‡©πŸ‡ͺ, EU
Playstore
Hitesh Sahu's apps on Google Play Store
Need Help?
Let's Connect
Navigation
Β  Home/About
Β  Skills
Β  Work/Projects
Β  Lab/Experiments
Β  Contribution
Β  Awards
Β  Art/Sketches
Β  Thoughts
Β  Contact
Links
Β  Sitemap
Β  Legal Notice
Β  Privacy Policy

Made with

NextJS logo

NextJS by

hitesh Sahu

| Β© 2026 All rights reserved.