Fundamentals 12 min read

Seven Fundamental Design Principles Behind Design Patterns

This article provides a comprehensive overview of design patterns by first explaining the seven core design principles—Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion, and others—detailing their definitions, benefits, UML diagrams, practical examples, and offering a downloadable PDF for deeper study.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Seven Fundamental Design Principles Behind Design Patterns

Regardless of the design pattern, it must follow solid design principles. While design patterns are concrete applications, design principles provide the theoretical guidance.

To grasp the essence of design patterns, one must first understand the seven major design principles.

This article focuses on the seven principles of design patterns.

Hello, I am mikechen. This is the final part of the "Seven Design Principles" series. For convenient study, the content has been compiled into a PDF titled "Deep Dive into Design Patterns" (~20,000 words, 81 pages, richly illustrated).

The material is useful for solidifying fundamentals and interview preparation; readers can download it at the end of the article.

Overview of Design Patterns

Design patterns (Design Pattern) are summaries of software development experience, offering reusable solutions for specific problem domains.

In simple terms, they reuse successful designs and architectures to solve recurring common problems.

There are 23 design patterns, each with distinct purposes and applicable scenarios.

Origin of Design Patterns

In 1995, the "Gang of Four" published the book "Design Patterns: Elements of Reusable Object‑Oriented Software," which first formalized 23 classic design patterns.

Benefits of Design Patterns

Design patterns improve code reusability, readability, reliability, and extensibility.

Encapsulate common functionality in reusable components, reducing redundancy.

Provide a structured way to organize code, lowering complexity.

Facilitate easy extension for new requirements without breaking existing code.

Seven Design Principles

The seven principles are: Single Responsibility Principle (SRP), Open/Closed Principle (OCP), Liskov Substitution Principle (LSP), Interface Segregation Principle (ISP), Dependency Inversion Principle (DIP), Law of Demeter (LoD), and Composite Reuse Principle (CRP). They aim for high cohesion and low coupling.

Single Responsibility Principle (SRP)

SRP states that a class should have only one responsibility, focusing on a single functionality, which reduces complexity and improves maintainability.

Difficulty lies in clearly delineating responsibilities and avoiding over‑splitting or over‑grouping.

When a change affects only one responsibility, the class should be split; otherwise, splitting is unnecessary.

Open/Closed Principle (OCP)

OCP asserts that software entities should be open for extension but closed for modification, enabling plug‑in extensions without altering existing code.

Example: a chart‑drawing system that supports multiple chart types without modifying core code.

Liskov Substitution Principle (LSP)

LSP requires that objects of a subclass can replace objects of a superclass without affecting program correctness.

Violations lead to reduced reusability and increased coupling.

Dependency Inversion Principle (DIP)

DIP promotes programming to interfaces: high‑level modules should not depend on low‑level modules; both should depend on abstractions, and abstractions should not depend on details.

Illustrated with UML diagrams and a bakery example where the bakery (high‑level) depends on abstract bread interfaces rather than concrete bread classes.

Interface Segregation Principle (ISP)

ISP advises designing small, client‑specific interfaces rather than large, monolithic ones, reducing unnecessary dependencies.

Examples show how splitting interfaces prevents classes from implementing unused methods.

Law of Demeter (LoD)

LoD (Least Knowledge Principle) recommends that a module should only communicate with closely related modules, minimizing coupling and enhancing maintainability.

Composite Reuse Principle (CRP)

CRP encourages composition or aggregation over inheritance for code reuse, reducing class explosion and adhering to OCP.

Example: a vehicle classification system where using composition avoids creating multiple inheritance combinations.

Summary

This article thoroughly explains the seven design principles that underpin design patterns, covering their definitions, benefits, UML diagrams, practical examples, and providing a downloadable PDF for deeper study.

design patternssoftware architectureSOLIDprinciples
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.