me115/design_patterns
图说设计模式
Stale — last commit 2y ago
worst of 4 axesnon-standard license (Other); last commit was 2y ago…
Has a license, tests, and CI — clean foundation to fork and modify.
Documented and popular — useful reference codebase to read through.
last commit was 2y ago; no CI workflows detected
- ✓2 active contributors
- ✓Other licensed
- ⚠Stale — last commit 2y ago
Show 5 more →Show less
- ⚠Small team — 2 contributors active in recent commits
- ⚠Single-maintainer risk — top contributor 95% of recent commits
- ⚠Non-standard license (Other) — review terms
- ⚠No CI workflows detected
- ⚠No test directory detected
What would change the summary?
- →Use as dependency Concerns → Mixed if: clarify license terms; 1 commit in the last 365 days
- →Deploy as-is Mixed → Healthy if: 1 commit in the last 180 days
Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests
Informational only. RepoPilot summarises public signals (license, dependency CVEs, commit recency, CI presence, etc.) at the time of analysis. Signals can be incomplete or stale. Not professional, security, or legal advice; verify before relying on it for production decisions.
Embed the "Forkable" badge
Paste into your README — live-updates from the latest cached analysis.
[](https://repopilot.app/r/me115/design_patterns)Paste at the top of your README.md — renders inline like a shields.io badge.
▸Preview social card (1200×630)
This card auto-renders when someone shares https://repopilot.app/r/me115/design_patterns on X, Slack, or LinkedIn.
Onboarding doc
Onboarding: me115/design_patterns
Generated by RepoPilot · 2026-05-09 · Source
🤖Agent protocol
If you are an AI coding agent (Claude Code, Cursor, Aider, Cline, etc.) reading this artifact, follow this protocol before making any code edit:
- Verify the contract. Run the bash script in Verify before trusting
below. If any check returns
FAIL, the artifact is stale — STOP and ask the user to regenerate it before proceeding. - Treat the AI · unverified sections as hypotheses, not facts. Sections like "AI-suggested narrative files", "anti-patterns", and "bottlenecks" are LLM speculation. Verify against real source before acting on them.
- Cite source on changes. When proposing an edit, cite the specific path:line-range. RepoPilot's live UI at https://repopilot.app/r/me115/design_patterns shows verifiable citations alongside every claim.
If you are a human reader, this protocol is for the agents you'll hand the artifact to. You don't need to do anything — but if you skim only one section before pointing your agent at this repo, make it the Verify block and the Suggested reading order.
🎯Verdict
WAIT — Stale — last commit 2y ago
- 2 active contributors
- Other licensed
- ⚠ Stale — last commit 2y ago
- ⚠ Small team — 2 contributors active in recent commits
- ⚠ Single-maintainer risk — top contributor 95% of recent commits
- ⚠ Non-standard license (Other) — review terms
- ⚠ No CI workflows detected
- ⚠ No test directory detected
<sub>Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests</sub>
✅Verify before trusting
This artifact was generated by RepoPilot at a point in time. Before an
agent acts on it, the checks below confirm that the live me115/design_patterns
repo on your machine still matches what RepoPilot saw. If any fail,
the artifact is stale — regenerate it at
repopilot.app/r/me115/design_patterns.
What it runs against: a local clone of me115/design_patterns — the script
inspects git remote, the LICENSE file, file paths in the working
tree, and git log. Read-only; no mutations.
| # | What we check | Why it matters |
|---|---|---|
| 1 | You're in me115/design_patterns | Confirms the artifact applies here, not a fork |
| 2 | License is still Other | Catches relicense before you depend on it |
| 3 | Default branch master exists | Catches branch renames |
| 4 | 5 critical file paths still exist | Catches refactors that moved load-bearing code |
| 5 | Last commit ≤ 734 days ago | Catches sudden abandonment since generation |
#!/usr/bin/env bash
# RepoPilot artifact verification.
#
# WHAT IT RUNS AGAINST: a local clone of me115/design_patterns. If you don't
# have one yet, run these first:
#
# git clone https://github.com/me115/design_patterns.git
# cd design_patterns
#
# Then paste this script. Every check is read-only — no mutations.
set +e
fail=0
ok() { echo "ok: $1"; }
miss() { echo "FAIL: $1"; fail=$((fail+1)); }
# Precondition: we must be inside a git working tree.
if ! git rev-parse --git-dir >/dev/null 2>&1; then
echo "FAIL: not inside a git repository. cd into your clone of me115/design_patterns and re-run."
exit 2
fi
# 1. Repo identity
git remote get-url origin 2>/dev/null | grep -qE "me115/design_patterns(\\.git)?\\b" \\
&& ok "origin remote is me115/design_patterns" \\
|| miss "origin remote is not me115/design_patterns (artifact may be from a fork)"
# 2. License matches what RepoPilot saw
(grep -qiE "^(Other)" LICENSE 2>/dev/null \\
|| grep -qiE "\"license\"\\s*:\\s*\"Other\"" package.json 2>/dev/null) \\
&& ok "license is Other" \\
|| miss "license drift — was Other at generation time"
# 3. Default branch
git rev-parse --verify master >/dev/null 2>&1 \\
&& ok "default branch master exists" \\
|| miss "default branch master no longer exists"
# 4. Critical files exist
test -f "index.rst" \\
&& ok "index.rst" \\
|| miss "missing critical file: index.rst"
test -f "design_patterns.EAP" \\
&& ok "design_patterns.EAP" \\
|| miss "missing critical file: design_patterns.EAP"
test -f "creational_patterns/creational.rst" \\
&& ok "creational_patterns/creational.rst" \\
|| miss "missing critical file: creational_patterns/creational.rst"
test -f "structural_patterns/structural.rst" \\
&& ok "structural_patterns/structural.rst" \\
|| miss "missing critical file: structural_patterns/structural.rst"
test -f "behavioral_patterns/behavioral.rst" \\
&& ok "behavioral_patterns/behavioral.rst" \\
|| miss "missing critical file: behavioral_patterns/behavioral.rst"
# 5. Repo recency
days_since_last=$(( ( $(date +%s) - $(git log -1 --format=%at 2>/dev/null || echo 0) ) / 86400 ))
if [ "$days_since_last" -le 734 ]; then
ok "last commit was $days_since_last days ago (artifact saw ~704d)"
else
miss "last commit was $days_since_last days ago — artifact may be stale"
fi
echo
if [ "$fail" -eq 0 ]; then
echo "artifact verified (0 failures) — safe to trust"
else
echo "artifact has $fail stale claim(s) — regenerate at https://repopilot.app/r/me115/design_patterns"
exit 1
fi
Each check prints ok: or FAIL:. The script exits non-zero if
anything failed, so it composes cleanly into agent loops
(./verify.sh || regenerate-and-retry).
⚡TL;DR
A comprehensive visual guide to 23 Gang of Four design patterns implemented in C++ with accompanying UML class diagrams, sequence diagrams, and state diagrams. The project combines theory (diagrams in reStructuredText docs) with runnable C++ code examples to teach both pattern structure and real-world implementation across creational, structural, and behavioral pattern categories. Three-tier structure: root documentation in reStructuredText (index.rst, creational_patterns/, structural_patterns/, behavioral_patterns/ directories), design model in EA project file (design_patterns.EAP containing all UML diagrams), and compilable source code organized in code/ directory. Static assets (_static/) hold ~40 diagram PNG files. Build system uses Makefile and Sphinx for HTML generation.
👥Who it's for
Software engineers and students learning design patterns who need concrete C++ implementations paired with visual UML documentation. Particularly useful for developers transitioning from theoretical pattern knowledge to practical coding, or for those preparing to apply patterns in C++ projects.
🌱Maturity & risk
Moderately mature but dormant. The project is well-structured with complete documentation, EA model files (design_patterns.EAP), and working code compiled under gcc 4.6.2, but shows signs of age (older compiler version, no visible CI/CD setup, no recent activity data provided). It's suitable as an educational resource but not actively maintained.
Low risk for educational use, but implementation may be outdated. Code targets gcc 4.6.2 (released ~2011), so C++ standard compliance and modern compiler compatibility are uncertain. The single-language focus on C++ means limited applicability to polyglot teams. No visible test suite or CI pipeline exists, making verification of correctness against modern compilers unclear.
Active areas of work
No active development signal visible. The repository appears to be a completed educational project frozen in time, with no indication of ongoing PRs, issues, or commits. It functions as a static reference resource rather than an actively evolving codebase.
🚀Get running
Clone the repository, then read index.rst to navigate the documentation structure. To compile C++ examples: make in the code/ directory (requires gcc 4.6.2+). To generate HTML docs: make html (requires Sphinx). View diagrams in _static/ directory and UML model in design_patterns.EAP with Enterprise Architect.
Daily commands:
For C++ examples: navigate to code/, run make to compile. For documentation: run make html at repo root (requires Sphinx + sphinx_rtd_theme). View generated HTML in _build/html/index.html. No runtime server required; this is static documentation + compiled binaries.
🗺️Map of the codebase
index.rst— Main entry point for the design patterns documentation; all readers should start here to understand the book structure and learning objectivesdesign_patterns.EAP— EA project file containing all UML class diagrams and sequence diagrams for every design pattern discussed in the bookcreational_patterns/creational.rst— Core documentation covering creational patterns (Factory, Singleton, Builder, Abstract Factory); fundamental for understanding object creationstructural_patterns/structural.rst— Core documentation covering structural patterns (Adapter, Bridge, Decorator, Facade, Proxy); essential for understanding object compositionbehavioral_patterns/behavioral.rst— Core documentation covering behavioral patterns (Observer, State, Strategy, Command, Mediator); critical for understanding object collaborationcode/AbstractFactory/main.cpp— Representative implementation example demonstrating how abstract factory pattern is coded; exemplar for all pattern implementations in the codebaseMakefile— Build automation script that compiles all C++ design pattern examples across the codebase
🧩Components & responsibilities
- Documentation Layer (RST + Sphinx) (ReStructuredText, Sphinx, Read the Docs theme) — Explains each pattern using text, theory, and static UML diagrams; entry point for learning
- Failure mode: Broken RST syntax prevents HTML generation; missing image links cause broken diagrams in output
- UML Model Repository (EA Project) — undefined
🛠️How to make changes
Add a New Design Pattern Documentation
- Create a new RST file in the appropriate pattern category (creational_patterns/, structural_patterns/, or behavioral_patterns/) (
behavioral_patterns/newpattern.rst) - Add the pattern's UML class diagram and sequence diagrams as static images to _static/ (
_static/NewPattern.jpg) - Reference the new pattern RST file in the corresponding category's index (e.g., behavioral_patterns/behavioral.rst) by adding a toctree directive (
behavioral_patterns/behavioral.rst) - Create a new C++ implementation directory under code/ following the naming convention (e.g., code/NewPattern/) with header files and main.cpp (
code/NewPattern/main.cpp)
Add a New C++ Pattern Implementation
- Create a new directory under code/ with the pattern name (e.g., code/YourPattern/) (
code/YourPattern/) - Create abstract base class header files (e.g., AbstractClass.h) defining the pattern's interface (
code/YourPattern/Abstract.h) - Create concrete implementation headers (e.g., ConcreteClass1.h, ConcreteClass2.h) and corresponding .cpp files (
code/YourPattern/Concrete1.h) - Create main.cpp demonstrating usage of the pattern with instantiation and method calls (
code/YourPattern/main.cpp)
Add Diagram Assets for a Pattern
- Create or export UML class diagram as JPG to _static/ with naming convention PatternName.jpg (
_static/PatternName.jpg) - Create sequence diagram showing runtime object interaction as seq_PatternName.jpg (
_static/seq_PatternName.jpg) - For state-based patterns, create state diagram (state1.png, state2.png format) showing state transitions (
_static/state1.png) - Reference all diagram files in the corresponding RST documentation file using image directives (
behavioral_patterns/pattern.rst)
🔧Why these technologies
- ReStructuredText (RST) — Standard documentation format for Python/technical projects; integrates seamlessly with Sphinx for automated HTML generation and publishing to ReadTheDocs
- Sphinx Documentation Generator — Automates conversion of RST source to professional HTML/PDF; enables cross-referencing between patterns and automatic index/TOC generation
- C++ (GCC 4.6.2) — Universal language for design pattern education; demonstrates patterns at low level with explicit class hierarchies and memory management
- Enterprise Architect (EA) UML Modeling — Professional UML tool for creating consistent, maintainable class and sequence diagrams across all 23 Gang of Four patterns
- Read the Docs (RTD) Theme — Provides clean, responsive HTML theme optimized for documentation reading; supports mobile and has good search/navigation UX
⚖️Trade-offs already made
-
Use static C++ examples instead of interactive simulations
- Why: Simplicity; teaches fundamental OOP concepts without runtime complexity
- Consequence: Readers must mentally execute code; no visual animation of object creation/interaction
-
Organize by pattern type (Creational/Structural/Behavioral) rather than difficulty
- Why: Aligns with Gang of Four classification; groups conceptually similar patterns
- Consequence: Must read all categories to see progression of complexity; no guided learning path from beginner→expert
-
Store UML diagrams as static JPG images rather than editable vector format in repo
- Why: Faster documentation build; diagrams are read-only for most users
- Consequence: EA project file is source-of-truth; diagram updates require EA tool + re-export cycle
-
Single monolithic EA project file (design_patterns.EAP) for all patterns
- Why: Centralized model; ensures consistency across all 23+ patterns
- Consequence: Large file size; difficult to version control; merging parallel edits is problematic
🚫Non-goals (don't propose these)
- Does not provide interactive/animated code execution
- Does not include testing frameworks or unit tests
- Does not cover architectural patterns (e.g., MVC, MVVM) beyond Gang of Four
- Does not include C++11/modern C++ examples; targets older GCC 4.6.2
- Does not provide pattern anti-patterns or common mistakes guide
- Not a compiler or runtime environment
🪤Traps & gotchas
Target compiler is gcc 4.6.2 (2011 era); modern gcc/clang may reject C++03/early-C++11 syntax or have stricter ABI compatibility. EA project file (.EAP) requires Enterprise Architect license to edit (open-source tool support varies). Sphinx theme (sphinx_rtd_theme) may be outdated; HTML generation may fail with modern Sphinx versions without dependency pinning. No makefile rules for cleaning or installing; be aware of stale build artifacts.
🏗️Architecture
💡Concepts to learn
- Gang of Four (GoF) Design Patterns — This repo teaches all 23 canonical patterns from the seminal 1994 book; understanding their taxonomy (creational/structural/behavioral) and relationships is foundational to reading any pattern documentation
- UML Class Diagrams & Sequence Diagrams — The core teaching method of this repo uses UML notation to visualize static structure and dynamic interaction; learning to read these diagrams is essential to comprehending pattern documentation and EA files
- Object-Oriented Design Principles (SOLID) — Design patterns in this repo implement or exemplify SOLID principles (Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion); many patterns exist to uphold these principles
- State Pattern & State Machines — This repo explicitly uses state diagrams (not just class/sequence diagrams) to explain the State pattern; understanding finite state machines helps recognize where State pattern applies
- C++ Memory Management (Raw Pointers vs. Smart Pointers) — The C++03-era code uses raw pointers and manual allocation; modern readers must understand why this approach was necessary then and how C++11+ smart pointers (std::shared_ptr, std::unique_ptr) change pattern implementation
- Template Method & Inheritance Hierarchies — Multiple patterns in the repo (Template Method, Factory Method, Strategy) rely on polymorphic base classes and virtual method dispatch; deep understanding of C++ vtables and inheritance is required
- Visitor Pattern & Double Dispatch — The Visitor pattern in behavioral_patterns implements double dispatch to overcome single-dispatch limitations in C++; this is a non-obvious technique unique to this pattern
🔗Related repos
refactoring-guru/design-patterns-cpp— Parallel design patterns resource with C++ code; more modern implementation and active maintenance; good for comparing explanations and code stylebkaradzic/ggez-goodies— Although game-focused, contains well-documented C++ pattern implementations with working examples; alternative reference for same patternsTheCherno/Hazel— Large C++ game engine with real-world design pattern usage (Factory, Observer, Command); demonstrates patterns in production code contextfacebookarchive/folly— Facebook's C++ utility library extensively uses design patterns (Singleton, Factory, Decorator, State); production-grade reference implementationgoogle/styleguide— Google C++ style guide frequently references design patterns and their idiomatic C++ implementation; companion for writing pattern code in modern C++
🪄PR ideas
To work on one of these in Claude Code or Cursor, paste:
Implement the "<title>" PR idea from CLAUDE.md, working through the checklist as the task list.
Add missing C++ code examples for Proxy, State, and Observer patterns
The repo contains comprehensive UML diagrams and sequence diagrams for all patterns (evidenced by seq_Proxy.jpg, seq_State.jpg, seq_Obeserver.jpg in _static/), but the code/ directory appears incomplete. Proxy, State, and Observer pattern implementations are missing their corresponding C++ source files, despite having detailed visual documentation. This creates a gap between the visual learning (step 1) and code implementation (step 2) that contributors should achieve.
- [ ] Create code/Proxy.cpp implementing the Proxy pattern shown in seq_Proxy.jpg and Proxy.jpg
- [ ] Create code/State.cpp with state transition implementations matching seq_State.jpg and seq_State_eg.jpg
- [ ] Create code/Observer.cpp (note: fix naming inconsistency from 'Obeserver' in image filenames) matching seq_Obeserver.jpg
- [ ] Ensure all three files compile under gcc 4.6.2 and include Makefile entries
- [ ] Verify implementations match the corresponding UML structure diagrams in _static/
Add CI workflow to validate C++ code compilation across pattern implementations
The repository contains 20+ C++ design pattern implementations in code/ that should compile under gcc 4.6.2 (as stated in README), but there is no automated validation. Given the Makefile exists and the project uses reStructuredText with Sphinx, adding a GitHub Actions workflow to compile all patterns and validate the build will catch regressions when contributors add new code examples or modify existing ones.
- [ ] Create .github/workflows/compile-patterns.yml with a job that installs gcc 4.6.2 (or closest available version)
- [ ] Add build step running
makein the code/ directory to compile all pattern implementations - [ ] Configure the workflow to run on push to main branches and pull requests
- [ ] Add status badge to README.rst showing compilation status
- [ ] Document compiler version requirements in .github/workflows/compile-patterns.yml comments
Create pattern index documentation linking visual diagrams to code examples
The repository has 40+ image files in _static/ (UML diagrams, sequence diagrams, class models, and run examples) organized by pattern, but no central index document that connects these visuals to the corresponding code files in code/. New contributors and readers struggle to navigate from a pattern's conceptual explanation to its concrete implementation. Creating an index file that maps each pattern to its diagram assets and code examples will improve discoverability.
- [ ] Create docs/pattern_index.rst listing all 20+ patterns with file references
- [ ] For each pattern entry, include: pattern name, link to class structure image (_static/_classModel.jpg or equivalent), link to sequence diagram (static/seq.jpg), link to implementation example (_static/*_run.jpg), and reference to code/ source file
- [ ] Include a visual relationship diagram reference (dp_relation.jpg) at the top
- [ ] Add cross-references in index.rst and ensure Sphinx builds without warnings
- [ ] Verify all 40+ images in _static/ are referenced in the new index document to identify any orphaned or mislabeled images
🌿Good first issues
- Modernize C++ implementations to C++17/20: update code/ examples to use auto, std::shared_ptr (instead of raw pointers), constexpr, and std::optional. Create a test harness to verify output against known diagrams.
- Add comprehensive doxygen-based API documentation to all C++ source files in code/ (currently none visible); generate and host alongside Sphinx docs for searchable cross-reference of implementation vs. diagram.
- Create a visual pattern selector tool (simple HTML/JavaScript) in _static/ or as separate index that lets users filter patterns by problem/intent/language, then links to relevant .rst and code files—improves discoverability for learners.
📝Recent commits
Click to expand
Recent commits
0cbd785— Merge pull request #7 from oxwsds/patch-1 (me115)57a8b55— Fix some typos (oxwsds)cc13852— update io design patterns (me115)a852f97— 修正排版错误 (me115)939987c— 添加在线浏览url (me115)8e0467c— 更新版权说明 (me115)808e23c— 去除中文 (me115)da08081— config 中文名去掉 (me115)15bf2f6— 将状态图文件改名 (me115)c628cc8— update readme (me115)
🔒Security observations
This is an educational repository containing design pattern documentation and C++ implementation examples. The codebase presents a LOW security risk profile as it is a static documentation and reference implementation project rather than production software. No critical vulnerabilities were identified. The repository contains: (1) Educational documentation in reStructuredText format, (2) C++ source code examples for design patterns compiled with GCC 4.6.2, (3) UML diagrams and images, and (4) No external dependencies, configuration files, credentials, or runtime infrastructure. The primary considerations are: outdated compiler version (GCC 4.6.2 from ~2012), lack of input validation in example code (expected for educational purposes), and potential code injection risks in C++ examples if used as production templates. The repository is appropriately scoped as educational material and poses minimal security risk in its intended use case.
LLM-derived; treat as a starting point, not a security audit.
👉Where to read next
- Open issues — current backlog
- Recent PRs — what's actively shipping
- Source on GitHub
Generated by RepoPilot. Verdict based on maintenance signals — see the live page for receipts. Re-run on a new commit to refresh.