Design Patterns & SOLID: Plain-Language Principles & Clean Refactoring

Last Audited: 2026-08-18
Tier-1 Platform Core
In Plain Language

Component-level design principles, YAGNI, and the SOLID principles explained in plain language with before/after TypeScript code refactoring.

Design Principles: Writing Code That Humans & Compilers Can Maintain

Design patterns are reusable solutions to common software design problems. However, memorizing design pattern names is useless without understanding the fundamental principles that make code flexible, testable, and resilient against regressions. Every principle on this page begins with a plain-language mental model before introducing technical terminology.

Two Pragmatic Guardrails: YAGNI & DRY

1. “Build for today, not for imaginary futures”

YAGNI

You Aren't Gonna Need It (YAGNI): Never write speculative abstractions, generic plugin architectures, or unused configuration fields until a concrete requirement demands them.

Prevents over-engineering and reduces attack surface.

2. “Every piece of knowledge has a single source”

DRY

Don't Repeat Yourself (DRY): Business logic and validation rules should exist in one authoritative place, preventing synchronization bugs when formulas change.

Note: Do not sacrifice readability to eliminate harmless cosmetic duplication.
Plain-Language Design Principles

The SOLID Principles: Clean Code Architecture

Intuitive Rule (Plain Language)

Do one job and do it well

Formal Engineering Term: Single Responsibility Principle (SRP)

A class or module should have one, and only one, reason to change. Separate data persistence, business calculation, and user notification into distinct components.

TypeScript Refactoring Comparison
// ✓ GOOD: Isolated single-responsibility services
class AssessmentScoreCalculator {
  calculateTotal(scores: number[]): number {
    return scores.reduce((a, b) => a + b, 0);
  }
}
class AssessmentRepository {
  async save(patientId: string, totalScore: number): Promise<void> { /* DB query */ }
}
class PatientNotifier {
  async notifyScoreReady(email: string): Promise<void> { /* Email dispatch */ }
}
Design Note: Separating concerns allows testing the score calculation algorithm purely in-memory with zero database or network dependencies.
Figure 6.1 — Core Modular Design Principles

High Cohesion & Loose Coupling vs. Spaghetti Anti-Pattern

High Cohesion and Loose Coupling ComparisonSide-by-side architectural diagram comparing clean modular decoupled services with tight cohesion on the left versus tightly-coupled spaghetti dependencies on the right.HIGH COHESION & LOOSE COUPLINGAuth & Session Service[Single Domain: Token Security]Clean API PortPatient Vitals Service[Single Domain: Clinical Ingestion]✓ Low defect cascades & easy refactoringTIGHT COUPLING (SPAGHETTI)Auth + DB + UI(Mixed Logic)Vitals + Mail(Direct DB write)Billing Helper❌ Changing 1 module breaks 3 others

High Cohesion & Loose Coupling

Cohesion means everything inside a single module works together toward one clear purpose (e.g. JWT validation only). Loose Coupling means modules only talk across clean, public interface ports without reaching into each other's internal data structures.

✓ Enables independent deployment, automated unit testing, and safe refactoring.
Try This With AI: SOLID Code Refactoring Assistant
SOLID Refactor Prompt

Use this prompt to audit and refactor legacy TypeScript classes for SOLID compliance:

"Act as a Principal Software Craftsmanship Engineer. Analyze the following class/module: [PASTE LEGACY CODE]. Audit it against the 5 SOLID principles: (1) Identify Single Responsibility violations, (2) Refactor if/else type switches into an Open-Closed Strategy pattern, (3) Extract bloated interfaces into focused contracts, (4) Apply Dependency Inversion for external I/O, and (5) Provide complete before/after TypeScript code."

Community Discussion & Feedback

Attributed peer feedback and official Netspective architecture notes.

Was this documentation helpful?(100% found this helpful • 0 ratings)

Leave Feedback or Question

○ Loading user info...
0/2000 chars

Discussion (0)

Loading discussion thread...