Decouple abstraction from implementation so both can vary independently
When to Use
You want to avoid a combinatorial explosion of classes when abstractions and implementations vary orthogonally
The implementation should be swappable at runtime (e.g., different rendering backends)
You need to extend both the abstraction and the implementation hierarchies independently
Instructions
Separate the abstraction (high-level logic) from the implementation (low-level detail).
The abstraction holds a reference to an implementation object.
Both can be subclassed independently — new abstractions do not require new implementations and vice versa.
Inject the implementation via the constructor.
// Implementation interface
class Renderer {
renderCircle(radius) {
throw new Error('Not implemented');
}
}
class SVGRenderer extends Renderer {
renderCircle(radius) {
return `<circle r="${radius}"/>`;
}
}
class CanvasRenderer extends Renderer {
renderCircle(radius) {
return `ctx.arc(0,0,${radius},0,2*PI)`;
}
}
// Abstraction
class Shape {
constructor(renderer) {
this.renderer = renderer;
}
}
class Circle extends Shape {
constructor(radius, renderer) {
super(renderer);
this.radius = radius;
}
draw() {
return this.renderer.renderCircle(this.radius);
}
}
Details
The Bridge pattern separates an abstraction from its implementation so that the two can evolve independently. Without Bridge, combining M abstractions with N implementations requires M*N classes. With Bridge, it requires M + N.
Trade-offs:
More complex initial setup — two parallel hierarchies
Adds indirection — the abstraction delegates to the implementation
Over-engineering for simple cases with one abstraction and one implementation
When NOT to use:
When there is only one implementation — just use it directly
When the abstraction and implementation are tightly coupled and always change together
For simple delegation — a function parameter is clearer than the full Bridge structure
Read the instructions and examples in this document.
Apply the patterns to your implementation, adapting to your specific context.
Verify your implementation against the details and edge cases listed above.
Harness Integration
Type: knowledge — this skill is a reference document, not a procedural workflow.
No tools or state — consumed as context by other skills and agents.
Success Criteria
The patterns described in this document are applied correctly in the implementation.
Edge cases and anti-patterns listed in this document are avoided.
1---2name: js-bridge-pattern3description: JS Bridge Pattern4metadata:5 source: https://skillmd.com/skills/intense-visions/js-bridge-pattern6---7# JS Bridge Pattern89> Decouple abstraction from implementation so both can vary independently1011## When to Use1213- You want to avoid a combinatorial explosion of classes when abstractions and implementations vary orthogonally14- The implementation should be swappable at runtime (e.g., different rendering backends)15- You need to extend both the abstraction and the implementation hierarchies independently1617## Instructions18191. Separate the abstraction (high-level logic) from the implementation (low-level detail).202. The abstraction holds a reference to an implementation object.213. Both can be subclassed independently — new abstractions do not require new implementations and vice versa.224. Inject the implementation via the constructor.2324```javascript25// Implementation interface26class Renderer {27 renderCircle(radius) {28 throw new Error('Not implemented');29 }30}3132class SVGRenderer extends Renderer {33 renderCircle(radius) {34 return `<circle r="${radius}"/>`;35 }36}3738class CanvasRenderer extends Renderer {39 renderCircle(radius) {40 return `ctx.arc(0,0,${radius},0,2*PI)`;41 }42}4344// Abstraction45class Shape {46 constructor(renderer) {47 this.renderer = renderer;48 }49}5051class Circle extends Shape {52 constructor(radius, renderer) {53 super(renderer);54 this.radius = radius;55 }56 draw() {57 return this.renderer.renderCircle(this.radius);58 }59}60```6162## Details6364The Bridge pattern separates an abstraction from its implementation so that the two can evolve independently. Without Bridge, combining M abstractions with N implementations requires M\*N classes. With Bridge, it requires M + N.6566**Trade-offs:**6768- More complex initial setup — two parallel hierarchies69- Adds indirection — the abstraction delegates to the implementation70- Over-engineering for simple cases with one abstraction and one implementation7172**When NOT to use:**7374- When there is only one implementation — just use it directly75- When the abstraction and implementation are tightly coupled and always change together76- For simple delegation — a function parameter is clearer than the full Bridge structure7778## Source7980https://patterns.dev/javascript/bridge-pattern8182## Process83841. Read the instructions and examples in this document.852. Apply the patterns to your implementation, adapting to your specific context.863. Verify your implementation against the details and edge cases listed above.8788## Harness Integration8990- **Type:** knowledge — this skill is a reference document, not a procedural workflow.91- **No tools or state** — consumed as context by other skills and agents.9293## Success Criteria9495- The patterns described in this document are applied correctly in the implementation.96- Edge cases and anti-patterns listed in this document are avoided.
Run npx get-skill add intense-visions/js-bridge-pattern in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
JS Bridge Pattern It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. Capability flags: docs only. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Intense-Visions (@intense-visions) published this skill. Their other Agent Skills are listed on their SkillMD profile.