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 Pattern4---5# JS Bridge Pattern67> Decouple abstraction from implementation so both can vary independently89## When to Use1011- You want to avoid a combinatorial explosion of classes when abstractions and implementations vary orthogonally12- The implementation should be swappable at runtime (e.g., different rendering backends)13- You need to extend both the abstraction and the implementation hierarchies independently1415## Instructions16171. Separate the abstraction (high-level logic) from the implementation (low-level detail).182. The abstraction holds a reference to an implementation object.193. Both can be subclassed independently — new abstractions do not require new implementations and vice versa.204. Inject the implementation via the constructor.2122```javascript23// Implementation interface24class Renderer {25 renderCircle(radius) {26 throw new Error('Not implemented');27 }28}2930class SVGRenderer extends Renderer {31 renderCircle(radius) {32 return `<circle r="${radius}"/>`;33 }34}3536class CanvasRenderer extends Renderer {37 renderCircle(radius) {38 return `ctx.arc(0,0,${radius},0,2*PI)`;39 }40}4142// Abstraction43class Shape {44 constructor(renderer) {45 this.renderer = renderer;46 }47}4849class Circle extends Shape {50 constructor(radius, renderer) {51 super(renderer);52 this.radius = radius;53 }54 draw() {55 return this.renderer.renderCircle(this.radius);56 }57}58```5960## Details6162The 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.6364**Trade-offs:**6566- More complex initial setup — two parallel hierarchies67- Adds indirection — the abstraction delegates to the implementation68- Over-engineering for simple cases with one abstraction and one implementation6970**When NOT to use:**7172- When there is only one implementation — just use it directly73- When the abstraction and implementation are tightly coupled and always change together74- For simple delegation — a function parameter is clearer than the full Bridge structure7576## Source7778https://patterns.dev/javascript/bridge-pattern7980## Process81821. Read the instructions and examples in this document.832. Apply the patterns to your implementation, adapting to your specific context.843. Verify your implementation against the details and edge cases listed above.8586## Harness Integration8788- **Type:** knowledge — this skill is a reference document, not a procedural workflow.89- **No tools or state** — consumed as context by other skills and agents.9091## Success Criteria9293- The patterns described in this document are applied correctly in the implementation.94- Edge cases and anti-patterns listed in this document are avoided.
Run npx skillmds@latest 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: makes network calls. 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.