Observer and strategy patterns
Two behavioural design patterns you use daily without naming them: the observer, for notifying many listeners when something happens, and the strategy, for swapping algorithms at run time, with Java examples, lambdas, and the pitfalls of each.
CodexBash, , 4 min read
Some design patterns describe how objects are created; others describe how they behave and talk to each other. Two of the most useful behavioural patterns are the observer, which lets many parts of a program react when something happens without the source knowing about them, and the strategy, which lets you swap one algorithm for another without changing the code that uses it. You already use both: every click handler is an observer, and every comparator passed to a sort is a strategy.
Sign in to read the rest
The whole 4 minute article is free with an account, along with every problem, lesson and tutorial. No card.