Chapter 7 of 10All chapters
Chapter 7 of 10
Design patterns
Named solutions to recurring shapes.
A few worth knowing
Strategy swaps an algorithm behind an interface. Adapter makes one interface look like another. Observer notifies interested parties. Factory decides which type to create.
- Patterns are vocabulary first: they let two people discuss a design quickly.
- Singleton is the one that causes the most trouble, because it hides a global.
Do not go looking
Patterns should be recognised in code that already needs them, not imposed in advance. Applying a pattern to a problem that does not have it adds indirection and nothing else.