33 lines
1.1 KiB
Markdown
33 lines
1.1 KiB
Markdown
# Bridge Design Pattern — Java Example
|
||
|
||
**Pattern:** Structural → Bridge
|
||
**Article:** https://ankurm.com/bridge-design-pattern-java/
|
||
|
||
## What this example shows
|
||
|
||
Decouples remote controls (Abstraction) from devices (Implementation). A basic remote and an advanced remote each work with any device (TV, Radio) without creating N×M subclasses.
|
||
|
||
## How to run
|
||
|
||
```bash
|
||
javac bridge/*.java -d out/bridge
|
||
java -cp out/bridge bridge.Main
|
||
```
|
||
|
||
Requires Java 25.
|
||
|
||
## Post Section ↔ File Mapping
|
||
|
||
| Post Section | File(s) |
|
||
|---|---|
|
||
| Step 1 — The Implementor Interface | `Device.java` |
|
||
| Step 2 — Concrete Implementors (TV and Radio) | `TV.java`, `Radio.java` |
|
||
| Step 3 — The Abstraction (RemoteControl) | `RemoteControl.java` |
|
||
| Step 4 — Refined Abstraction (AdvancedRemote) | `AdvancedRemote.java` |
|
||
| Wiring It Together: Main Demo | `Main.java` |
|
||
|
||
Note: the "Class Explosion Problem — Visualised" pseudocode and the JDBC/SLF4J snippets shown in the article are illustrative only — they are not part of this repository's runnable example.
|
||
|
||
Article: https://ankurm.com/bridge-design-pattern-java/
|
||
All patterns: https://ankurm.com/design-patterns-java/
|