Posts

Java Command and Template Method Patterns: Encapsulate Requests and Algorithms

Maya's shop has grown past the checkout. Two admin jobs now eat her staff's mornings. The first is the product-description editor: a member of staff rewrites a book's description, a slip deletes a paragraph, and there is no way back — the old text is gone, and the only fix is retyping it from memory. The second is the nightly supplier import: two suppliers send catalogues in different formats — one comma-separated lines, the other JSON — and every format has its own copy of the same four steps: open, parse, check, store. A fix to the checking step has to be made twice, and last month it was made once. That is the problem. Post 1 asked what varies? Post 2, Java Singleton Pattern: Enum, Lazy Holder & Double-Checked Locking Explained , asked how many? Post 3, Java Factory Pattern: Factory Method vs Abstract Factory With Examples , asked who decides which object gets created? Post 4, Java Builder Pattern: Build Complex Objects Without Telescoping Constructors , asked h...

Java Strategy and State Patterns: Swap Behavior at Runtime

Maya's bookstore sells online now, and the checkout takes three kinds of payment — card, wallet, and cash on delivery. A fourth is coming: gift cards, for the holidays. Every new method means the same edit: another branch in the checkout's if-chain, another round of re-testing what already works. And the orders themselves are tracked with a status flag — a string that says NEW or PAID or SHIPPED — checked by an if-chain in every method. The checkout knows every payment method by name, and the order's life is a string anyone can rewrite. That is the problem. Post 1 asked what varies? Post 2, Java Singleton Pattern: Enum, Lazy Holder & Double-Checked Locking Explained , asked how many? Post 3, Java Factory Pattern: Factory Method vs Abstract Factory With Examples , asked who decides which object gets created? Post 4, Java Builder Pattern: Build Complex Objects Without Telescoping Constructors , asked how do you assemble one object, piece by piece? Post 5, Java Adapt...

Java Observer Pattern: Events, Listeners and Reactive Design Explained

Maya's bookstore is part of a small chain, and the staff dashboard shows the chain's share price — one number, watched by three things. A display on the wall shows the current price. An alert fires when the price crosses 150. A log records every change, so the support desk can answer "what was the price at noon?" The catch: new watchers keep arriving — a second display, a weekly report — and every one of them means an edit to the code that sets the price. The ticker knows its listeners by name, and that is the problem. Post 1 asked what varies? Post 2, Java Singleton Pattern: Enum, Lazy Holder & Double-Checked Locking Explained , asked how many? Post 3, Java Factory Pattern: Factory Method vs Abstract Factory With Examples , asked who decides which object gets created? Post 4, Java Builder Pattern: Build Complex Objects Without Telescoping Constructors , asked how do you assemble one object, piece by piece? Post 5, Java Adapter and Facade Patterns: Integrate...

Java Decorator and Proxy Patterns: Add Behavior Without Changing Classes

Maya's bookstore now sends order confirmations by email, and the shop has two new requirements. First, every confirmation must be logged — so the support desk can answer "did the email go out?" — and retried when the mail server is busy, instead of lost. Second, the shop's price list lives behind a document service: anyone may read it, only an editor may change it. The catch: the sender and the document service already work, and nobody wants to rewrite either class — or paste the same logging, retry, and access check into every caller. Post 1 asked what varies? Post 2, Java Singleton Pattern: Enum, Lazy Holder & Double-Checked Locking Explained , asked how many? Post 3, Java Factory Pattern: Factory Method vs Abstract Factory With Examples , asked who decides which object gets created? Post 4, Java Builder Pattern: Build Complex Objects Without Telescoping Constructors , asked how do you assemble one object, piece by piece? Post 5, Java Adapter and Facade Pa...