Gof Strategy

Strategy in modern Java, separated into three things that are usually conflated: the design concept (an algorithm varies), the classical class hierarchy, and the lambda or functional interface that expresses it today. Covers when a function value is enough and when a named type earns its keep, selecting a strategy by key instead of an if-else chain, the trap of strategies that differ only in constants and may be configuration, how shared state changes concurrency obligations, and the contract test implementations can share. Use when an algorithm must vary at runtime, when a switch over a type code keeps growing, when a class hierarchy exists whose members are one-line methods, or when strategy classes differ only in a rate or a threshold. Does not cover behaviour that changes with the object's own state (gof-state), two independently varying hierarchies (gof-bridge), an algorithm skeleton with varying steps (gof-template-method), or choosing which object to create (gof-factory-method).

robsonkades Updated

File contents

robsonkades/agent-skills/tree/main/skills/gof-strategy commit 55e156bdc6

Frequently asked questions

npx skillmds@latest add robsonkades/gof-strategy