How alainmnts/adapter-pattern works
This is a small Java Adapter-pattern demonstration: Main creates three device/adapter pairs, then invokes each through the PowerOutlet interface. Each adapter translates plugIn() into its adaptee’s device-specific operation, which prints a status message. Although the README describes compatibility and safety concerns, the sampled implementation does not model voltage or amperage checks.
Main entry points: Main.java Application entry · PowerOutlet.java PowerOutlet · LaptopAdapter.java LaptopAdapter · Laptop.java Laptop
Components 10
Other components
- User
- Application entry
src/Main.java - PowerOutlet
src/PowerOutlet.java - LaptopAdapter
src/LaptopAdapter.java - Laptop
src/Laptop.java - RefrigeratorAdapter
src/RefrigeratorAdapter.java - Refrigerator
src/Refrigerator.java - SmartphoneAdapter
src/SmartphoneAdapter.java - SmartphoneCharger
src/SmartphoneCharger.java - Console output
Connections 17
- User → Application entry: runs
- Application entry → LaptopAdapter: constructs
- Application entry → Laptop: constructs
- Application entry → RefrigeratorAdapter: constructs
- Application entry → Refrigerator: constructs
- Application entry → SmartphoneAdapter: constructs
- Application entry → SmartphoneCharger: constructs
- Application entry → PowerOutlet: invokes plugIn
- PowerOutlet → LaptopAdapter: dispatches
- PowerOutlet → RefrigeratorAdapter: dispatches
- PowerOutlet → SmartphoneAdapter: dispatches
- LaptopAdapter → Laptop: calls charge
- RefrigeratorAdapter → Refrigerator: calls startCooling
- SmartphoneAdapter → SmartphoneCharger: calls chargePhone
- Laptop → Console output: prints status
- Refrigerator → Console output: prints status
- SmartphoneCharger → Console output: prints status