搜索

PythonReactSEOPDF
GitHub Skill

design-pattern-bridge

Use when abstractions and implementations need to evolve independently without creating subclass explosion.

zenobi-us☆ 39 仓库 Stars7 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

Skill: Bridge

Intent

Decouple an abstraction from its implementation so both can vary independently through composition instead of multiplying inheritance combinations.

Applicability Signals

  • Signal 1: Inheritance trees are growing by combining two independent dimensions (for example, shape × renderer).
  • Signal 2: New variants in one dimension force code changes and retesting across the other dimension.
  • Signal 3: Runtime swapping of implementations is valuable for environment, performance, or platform concerns.

Contraindications

  • Case 1: Only one stable implementation exists and no second dimension of change is expected.
  • Case 2: Composition boundary would add indirection with no measurable flexibility gain.
  • Case 3: Team lacks discipline to keep abstraction and implementation contracts small and coherent.

Decision Heuristics

  • If two axes of variation are independent and actively changing, prefer Bridge.
  • If you only need one simple compatibility layer, Adapter is usually sufficient.
  • Decision anti-bias note: do not split abstraction/implementation unless variation pressure is real.

Implementation Checklist

  • Identify abstraction-facing operations and implementation-facing operations.
  • Define implementation interface with minimal required primitives.
  • Refactor abstraction to delegate implementation work through composition.
  • Add refined abstractions only where behavior differs at abstraction layer.
  • Test independent extension on both abstraction and implementation sides.

Misuse Checks

  • Misuse 1: Abstraction exposes implementation-specific details → Remediation: tighten abstraction API and hide impl contracts.
  • Misuse 2: Implementation interface becomes bloated catch-all → Remediation: split interfaces by capability.
  • Misuse 3: Bridge used when only one side varies → Remediation: simplify to strategy/adapter/plain composition.

Verification Rubric

  • Correctness:
    • Baseline abstraction delegates correctly to implementation.
    • Swapping implementation changes behavior without abstraction rewrite.
  • Design quality:
    • Abstraction and implementation interfaces are independently understandable.
    • Cross-product subclass explosion is removed or prevented.
  • Regression safety:
    • Tests cover one abstraction with multiple implementations and one implementation with multiple abstractions.

Language-Specific Adaptations (Optional)

  • TypeScript: use interface contracts for implementor; inject implementation in constructor.
  • Python: use composition and protocols/ABCs; avoid deep multiple inheritance.
  • Go: define implementor interface; wire concrete implementors in constructors.

Related Patterns (Optional)

  • Strategy: interchangeable algorithms behind one interface, usually without distinct abstraction hierarchy.
  • Adapter: converts incompatible interfaces rather than separating two variation axes.

Attribution & Sources

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-03-11
索引更新时间
2026-03-11
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!