15
Adapter, Facade, Bridge, and PImpl
One carrier integration carried through four structural techniques, from wrapping a legacy API to a compilation firewall.
One GlobalFreight carrier integration carried through four structural techniques:
- Adapter.
LegacyFreightRateAdapterobject-composes a legacy rate API, translating kilograms to grams and destination zones to the legacy zone codes so the client sees the book’sRateSourceinterface. - Facade.
ShippingFacade::quote_and_label()sequences rating, labeling, and tracking in one call so the client does not orchestrate the subsystems. - Bridge. A
Notificationabstraction crosses aNotificationTransportimplementation axis: two refined kinds times two transports, four combinations, with no class explosion. - PImpl.
LabelRendererhides its implementation behind a pointer; a test assertssizeof(LabelRenderer) == sizeof(void*).
A C++23 try_quote_and_label() returning std::expected is guarded for C++20.
Build, run, observe
./scripts/build.sh cpp23
./scripts/verify.sh cpp23 # 17/17 tests pass
./examples/15-adapter-facade-bridge/demo.sh cpp23
The demo quotes through the adapted legacy API, produces a label through the
facade, and sends notifications across both transports. Chapter 15 distinguishes
the four techniques and when each fits. Builds standalone and under the cpp20
preset (15 tests).