Tagged “Structural”
9 articles with this tag.
- AdapterConvert an interface you cannot change into the one your code expects. A runnable Java 21 example wraps a legacy payment SDK, translating units, status codes and exceptions — plus class versus object adapters, trade-offs and interview questions.
- Adapter vs Decorator vs Proxy vs FacadeFour structural patterns that all wrap other objects. The one question that tells them apart, side-by-side Java sketches, and how to answer the classic interview question.
- GoF OverviewA map of the 23 Gang of Four design patterns: the three categories, class versus object scope, one-line intents, JDK examples, and how to choose between patterns that look alike.
- BridgeSplit a class that varies in two independent dimensions into two hierarchies connected by composition, so they can evolve separately. A runnable Java 21 notification example (alerts and digests × email and SMS), Bridge versus Adapter and Strategy, trade-offs and interview questions.
- CompositeCompose objects into tree structures and treat single objects and groups uniformly. A runnable Java 21 product-bundle example with nested discounts, transparency versus safety, sealed interfaces, and where Composite appears in the JDK, Spring and UI frameworks.
- DecoratorAdd responsibilities to an object dynamically by wrapping it in objects with the same interface. A runnable Java 21 HTTP client stacked with logging, caching and retry decorators, why order matters, java.io as the classic example, Decorator versus inheritance and proxies.
- FacadeGive a complex subsystem one simple entry point. A runnable Java 21 checkout facade coordinating inventory, payment, shipping and notifications with compensation, the Principle of Least Knowledge, Facade versus application service and API gateway, trade-offs and interview questions.
- FlyweightSupport huge numbers of fine-grained objects by sharing their common, immutable state. Intrinsic versus extrinsic state, a flyweight factory, a runnable Java 21 map-marker example sharing 3 styles across 100,000 markers, and Flyweight in the JDK (Integer cache, String interning).
- ProxyControl access to an object through a stand-in with the same interface. Virtual, protection, caching and remote proxies in a runnable Java 21 example, JDK dynamic proxies, how Spring's @Transactional and lazy JPA associations rely on proxies, and Proxy versus Decorator.