Skip to content

Commit be8fea5

Browse files
committed
Code-Beispiel für das Bridge-Pattern in JavaScript
1 parent a546cff commit be8fea5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Abstraction
2+
class GUIComponent {
3+
constructor(platform) {
4+
this.platform = platform;
5+
}
6+
7+
render() {
8+
this.platform.render();
9+
}
10+
}
11+
12+
// Implementation
13+
class WindowsGUI {
14+
render() {
15+
console.log('Rendering GUI component on Windows...');
16+
}
17+
}
18+
19+
class MacOSGUI {
20+
render() {
21+
console.log('Rendering GUI component on MacOS...');
22+
}
23+
}
24+
25+
// Usage
26+
const windowsGUIComponent = new GUIComponent(new WindowsGUI());
27+
windowsGUIComponent.render(); // Output: "Rendering GUI component on Windows..."
28+
29+
const macosGUIComponent = new GUIComponent(new MacOSGUI());
30+
macosGUIComponent.render(); // Output: "Rendering GUI component on MacOS..."

0 commit comments

Comments
 (0)