Hitesh Sahu
Hitesh SahuHitesh Sahu
  1. Home
  2. โ€บ
  3. posts
  4. โ€บ
  5. โ€ฆ

  6. โ€บ
  7. 1.4 Priciple

Loading โณ
Fetching content, this wonโ€™t take longโ€ฆ


๐Ÿ’ก Did you know?

๐Ÿฆฅ Sloths can hold their breath longer than dolphins ๐Ÿฌ.

๐Ÿช 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

Cover Image for ๐Ÿ’ป Principles of 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.

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

Tue Nov 11 2025

Share This on

๐Ÿ’ป 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.

Programming/1.4-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

| ยฉ 2025 All rights reserved.