Which pattern, when 00:00:00 Make a prediction You will choose a design pattern by identifying what varies and who chooses it, then explain when a plain conditional is sufficient. Standard and express shipping use different formulas. A locked parcel cabinet also changes what it will do after a valid code. Are these the same kind of variation? Shipping rules are interchangeable choices for a request. The cabinet's response depends on its own history. The first points toward Strategy; the second points toward explicit states and legal transitions. 00:00:34 Asha, the ring and the doors A guide carries a ring of keys. Looking at the shape of the lock lets her pick one key. Counting how many keys she owns tells her nothing about which door will open. Patterns are choices for a particular force. Inspect the lock: incompatible interfaces, variable policies, independent dimensions or a changing state. Trying every key makes a simple design harder to use. A design pattern is a named answer to a problem that comes back in many programs, together with the situation it fits and the price it has. All four parts matter. A name without the situation is only a word. In a design round people often name patterns first and look for a place to put them afterwards. The result has more classes than the problem has facts. Starting from the force stops that, because no force means no pattern. 00:01:26 Choose a shipping rule A store needs standard and express shipping for the same basket. Only the pricing calculation varies. Pass the chosen policy into checkout and ask it to quote the basket. Checkout still owns the purchase flow. Add a weekend policy and run the original checkout tests with all three. An unchanged caller is evidence the separation solves this variation. Keep the basket and its contents identical. Ask standard shipping for a price, then inject express and ask again. The customer selects the service; the checkout follows the same steps in both runs. If shipping changes automatically after payment, that requirement introduces a different source of variation. 00:02:10 State changes the available action A locked parcel locker must refuse pickup until the correct code arrives. Its behaviour changes because of the locker's history, rather than a policy the caller selects. Draw locked, authorized and collected states. That comparison explains when State helps more than Strategy. Try an incorrect pickup code, a correct one, and then the same correct one again after collection. The middle input can unlock the compartment, while the third cannot collect a second parcel. The input stayed identical; the object's own prior state changed its legal next action. A single fixed shipping calculation does not earn a strategy registry. You would be adding indirection with no independent variation. A transition table can express a small state machine clearly even if no state objects are instantiated. Java Comparator: Strategy. A comparator is an object that orders two values. It can be passed to Collections.sort, so the sorting code never changes when the order does. Force: the rule comes from outside. Java FilterInputStream: Decorator. It wraps some other input stream, uses it as its source of data, and may add functionality. Buffering and decompression can be stacked in any mix. 00:03:34 Try an interview follow-up Why not make the parking lot a Singleton? One lot is a fact of the example. I create one in main and pass it on. A global instance hides dependencies, makes tests share data, and blocks a second lot later. A shop adds a different tax calculation for each region, while the steps for checking out stay fixed. Point to the part that varies. A replaceable tax policy fits this requirement. Ask what would make that choice unnecessary. If there is only one stable tax rule, a single function is a reasonable starting point. 00:04:11 What to take with you Ask what varies. If nothing varies, write the plain version. If something varies, name the force, try the cheaper answer first (a value, a function, a table), and use the pattern when the cheaper answer stops being enough. Keywords in the prompt are hints. different can mean Strategy, Factory or only a number. The answer to a follow-up question decides.