Skip to content

namecoder1/coding-principles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Software Design Principles Overview

A quick overview of four fundamental principles for writing clean, maintainable, and scalable code: SOLID, DRY, KISS, and YAGNI.


✅ 1. SOLID Principles

A set of five object-oriented design principles introduced by Robert C. Martin (Uncle Bob):

  1. S - Single Responsibility Principle (SRP)
    A class should have only one reason to change.
    ➤ One class = One responsibility.

  2. O - Open/Closed Principle (OCP)
    Software entities should be open for extension, but closed for modification.
    ➤ Add new features without modifying existing code (use abstraction and polymorphism).

  3. L - Liskov Substitution Principle (LSP)
    Subtypes must be substitutable for their base types.
    ➤ A subclass should behave like its parent class without breaking the program.

  4. I - Interface Segregation Principle (ISP)
    Many client-specific interfaces are better than one general-purpose interface.
    ➤ Classes should not be forced to implement methods they don’t use.

  5. D - Dependency Inversion Principle (DIP)
    Depend on abstractions, not on concrete implementations.
    ➤ High-level modules shouldn’t depend on low-level ones.


✅ 2. DRY - Don't Repeat Yourself

"Every piece of knowledge must have a single, unambiguous representation in the system."

  • Avoid duplicating code or logic.
  • Centralize reusable logic in a single place.

✔️ Good:

function calculateDiscount(price: number) {
  return price > 100 ? price * 0.1 : 0;
}

✅ 3. KISS - Keep It Simple, Stupid

“Simplicity is key to maintainability.”

  • Prefer simple and clear solutions over overly abstract or complex ones.
  • Don’t over-engineer unless it’s necessary.

✔️ Good:

function add(a: number, b: number) {
  return a + b;
}

✅ 4. YAGNI - You Aren’t Gonna Need It

“Don’t implement functionality until it’s actually needed.” • Avoid adding speculative features. • Focus only on the current requirements to keep the codebase lean.

✨ When combined

  • SOLID → Helps structure complex systems.
  • DRY → Keeps logic consistent.
  • KISS → Avoids unnecessary complexity.
  • YAGNI → Prevents writing unused code.

About

A small repo that shows the Must-Know Core Principles for software design

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published