Design Principles Tutorial 0/97 lessons ~6 min read Lesson 7

    Design Principles Myths

    Common myths — "SOLID always," "more interfaces = better," "DRY means no duplicate lines" — cause over-engineering.

    Course progress0%
    Focus
    24 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Common myths — "SOLID always," "more interfaces = better," "DRY means no duplicate lines" — cause over-engineering. Staff engineers debunk myths with trade-offs and context.

    Business problem

    Business pressure: Amazon's core platform must ship weekly while keeping incident rates below SLO. Without Design Principles Myths, teams accumulate coupling — every feature touches the same modules, regressions correlate, and senior hiring loops fail because candidates cannot articulate refactor trade-offs.

    • Velocity: Median PR size grows; cross-team coordination dominates delivery time.
    • Quality: Production incidents cluster around modules with multiple reasons to change.
    • Talent: Staff promotion cases require evidence of principled architecture decisions — not buzzwords.

    Architecture motivation

    Why architects care: Design Principles Myths addresses maintainability, change isolation, and testability. The naive alternative (God classes, concrete dependencies, duplicated business rules) works until team size and traffic make every change expensive and risky.

    • Force: Requirements change along different axes — tax law, UI, persistence, notifications.
    • Constraint: Cannot pause feature development for a multi-year rewrite.
    • Outcome: Clear boundaries, faster tests, principled code reviews, and ADRs that survive turnover.

    Real production story

    During a production incident at Amazon, a checkout regression traced to a God module that violated Design Principles Myths: one tax-rule change broke unrelated notification code. The post-incident refactor did not rewrite the system — it applied Design Principles Myths incrementally with characterization tests. PR cycle time on that domain dropped 40% within two quarters, and code review debates shifted from style to named principles.

    Enterprise case study

    Amazon — Design Principles Myths in production: Platform team inherited an 80k-line module where every feature violated basic separation. Incremental extractions behind interfaces, package acyclicity in CI, and principle-based review rubrics reduced change-failure rate 45% without a big-bang rewrite.

    • Before: Correlated regressions; reviews debated formatting.
    • Decision: Apply smallest refactor that improves testability and names the principle.
    • After: Faster unit tests, smaller PRs, staff-ready interview narratives.

    Refactoring walkthrough

    Incremental refactor sequence for Design Principles Myths — Martin Fowler's safe steps, not a rewrite:

    • 1. Characterize: Add tests capturing current behavior before moving code.
    • 2. Extract: Move the smallest cohesive unit; rename to reveal intent.
    • 3. Invert: Introduce interface at the boundary already mocked in tests.
    • 4. Wire: DI container or factory registers implementations.
    • 5. Document: ADR notes rejected alternatives and YAGNI deferrals.
    text
    // Design Principles Myths — illustrative refactor sketch
    // BEFORE: OrderFacade validates, prices, persists, emails (4 reasons to change)
    // AFTER:
    // OrderValidator — validation only (SRP)
    // PricingStrategy — discount rules (OCP)
    // OrderRepository — persistence port (DIP)
    // NotificationPort — email/SMS (ISP)
    // Tests: same public API; smaller units; fakes at boundaries

    Failure scenario

    What breaks when Design Principles Myths is ignored or misapplied:

    • Big-bang rewrite trap: Team freezes features for 9 months; business ships competitor features first.
    • Golden hammer: Strategy pattern for every if/else — YAGNI and readability suffer.
    • False DRY: Forced abstraction across unrelated domains — wrong coupling worse than duplication.

    Scalability analysis

    Scale dimensions: Design Principles Myths decisions compound across team count, codebase size, and deployment frequency — not just lines of code.

    • Team scale: Conway's Law — module boundaries should align with ownership.
    • Code scale: Package cycles block parallel development; enforce acyclic graphs in CI.
    • Change scale: Feature flags + incremental extraction beat monolithic refactors.

    Security considerations

    Security is structural: Design Principles Myths affects blast radius, secret handling, and auditability.

    • Boundary leaks: God classes mix auth logic with export code — privilege escalation paths hide in tangled methods.
    • Test doubles: DIP enables security unit tests without hitting real payment APIs in CI.
    • Supply chain: Stable abstractions reduce direct imports of vendor SDKs across the codebase.

    Architecture review questions

    • What is the single reason to change for the module under review (Design Principles Myths)?
    • Which principle is violated — and what is the smallest safe refactor?
    • Are tests sufficient to characterize behavior before extraction?
    • What trade-off are we accepting (indirection vs testability)?
    • Does this change align with package dependency rules and team ownership?
    • Is there an ADR if this is an architectural boundary shift?

    Staff engineer notes

    • Principle-based reviews convert subjective taste into teachable decisions — your job is to make the trade-off legible.
    • At Amazon scale, Design Principles Myths fails at boundaries: interfaces, test fakes, and package imports — not diagram aesthetics.
    • Good architecture is boring on the happy path and explicit on the failure path — if runbooks are fiction, the design is not production-ready.

    Interview questions

    What's wrong with this code regarding Design Principles Myths?(Intermediate)

    Identify the specific smell (e.g., multiple reasons to change), name the principle violated, propose extract/interface refactor steps, and mention characterization tests before moving code.

    Follow-up: What would you defer to avoid YAGNI?

    How does Design Principles Myths interact with DRY, KISS, and YAGNI?(Intermediate)

    Principles trade off: DRY removes duplicated knowledge; YAGNI avoids speculative abstraction; KISS prefers the simplest design that works. Sometimes temporary duplication is correct until the second use case proves the abstraction.

    Follow-up: Give an example where you'd duplicate once intentionally.

    Senior trade-off for Design Principles Myths in a legacy monolith?(Advanced)

    Indirection vs testability; team familiarity vs ideal dependency graph; incremental refactor vs rewrite risk. Measure success via change-failure rate, PR cycle time, and test execution speed — not file count.

    Follow-up: How would you land the first extraction in production?

    Hands-on refactoring exercise

    Refactoring exercise: Take a 200-line God class from your codebase (or the capstone module). Map smells to Design Principles Myths, write characterization tests, and perform one extraction that improves testability without changing public behavior.

    • Deliverable 1: Smell inventory mapped to principles.
    • Deliverable 2: Before/after dependency diagram.
    • Deliverable 3: One merged PR with tests green.

    In-depth explanation

    Core idea: Design Principles Myths guides how you structure code so that maintainability, change isolation, and testability. It is a force balancer — not a rule to maximize at all costs.

    • Definition: Design Principles Myths — durable guideline for structuring maintainable software.
    • Violation signals: God classes, shotgun surgery, feature envy, divergent change.
    • Refactor moves: Extract class, introduce interface, move method, replace conditional with polymorphism.
    • When to relax: Early prototype, throwaway spike, or truly trivial script — optimize for learning speed.

    Visual explanation

    Three diagrams: principle architecture, refactor workflow, and common violation patterns:

    Design Principles Myths design view
    Smell
    Code review
    Principle
    Name force
    Refactor
    Minimal change
    Verify
    Tests pass
    Design view — name the force before choosing a pattern or refactor.
    Design Principles Myths refactor workflow
    Read
    List smells
    Map
    SRP·DIP·DRY
    Propose
    Extract·interface
    Trade-off
    YAGNI·KISS
    Repeat in code review and interviews — smell, principle, fix, trade-off.
    Common violation patterns
    God class
    SRP break
    Concrete deps
    DIP break
    Copy-paste
    DRY break
    Over-abstract
    YAGNI break
    Map each smell to a principle — then propose the smallest safe refactor.

    Structural view

    Design Principles Myths — structural view:

    text
    Violation detected (Design Principles Myths)
    Name principle + axis of change
    Incremental refactor (Fowler catalog)
    Tests + simpler dependency graph

    Execution workflow

    1Design Principles Myths in design practice
    1 / 5

    Detect smell

    God class, duplication, wrong dependency direction.

    Use review checklist.

    Informative example

    Example — Design Principles Myths:

    text
    // Review prompt for Design Principles Myths
    // 1. What reasons to change does this module have?
    // 2. Which dependencies point the wrong direction?
    // 3. Smallest extraction that improves testability?
    // 4. What behavior must tests lock before refactor?

    Real-world use

    Uncle Bob's SOLID and Clean Architecture popularized dependency direction for enterprise systems. The Pragmatic Programmer's DRY, orthogonality, and tracer bullets shape daily craft. Martin Fowler's refactoring catalog turns principles into safe, incremental steps. Package design rules from Robert C. Martin and Rebecca Wirfs-Brock keep monorepos navigable. These ideas appear in Amazon's code review culture, Google readability standards, and Stripe's API design norms.

    Trade-offs

    • Pro: clearer change isolation, faster principled reviews, and interview-ready narratives.
    • Con: more types and indirection — hurts readability if over-applied.
    • Con: premature abstraction violates YAGNI — balance with KISS.

    Best practices

    • Map each review comment to a principle, not personal taste.
    • Characterization tests before extracting legacy God classes.
    • Enforce acyclic package dependencies in CI where possible.

    Anti-patterns

    • Myth: Clean code means more classes — reality: cohesion and clarity beat file count.
    • Myth: Principles are only for OOP — reality: functional modules have SRP and DIP too.
    • Myth: Refactoring is a separate project — reality: incremental daily habit.

    Common mistakes

    • SRP taken as "one public method" — misses axis of change.
    • DRY across unrelated domains — wrong abstraction worse than duplication.

    Summary

    Design Principles Myths at staff level means naming smells, proposing minimal tested refactors, and documenting trade-offs — the skill Amazon senior engineers demonstrate in every architecture review.

    Key takeaways

    • Design Principles Myths is a force balancer — apply with evidence, not dogma.
    • Production success depends on incremental refactors, tests, and explicit trade-offs.
    • Use this vocabulary in reviews and staff interviews with concrete smells and fixes.
    Ready to mark this lesson complete?Track your journey across the entire course.