31 lines
820 B
Markdown
31 lines
820 B
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
|
||
java bridge.Main
|
||
```
|
||
|
||
Requires Java 11+.
|
||
|
||
## Files
|
||
|
||
| File | Role |
|
||
|---|---|
|
||
| `Device.java` | Implementor interface |
|
||
| `TV.java` / `Radio.java` | Concrete Implementors |
|
||
| `RemoteControl.java` | Abstraction (holds Device bridge) |
|
||
| `AdvancedRemote.java` | Refined Abstraction |
|
||
| `Main.java` | Demo entry point |
|
||
|
||
Article: https://ankurm.com/bridge-design-pattern-java/
|
||
All patterns: https://ankurm.com/design-patterns-java/
|