Behavioral parameterization, a software development model that handles frequently changing requirements. Principle: After writing similar code, try to abstract it.
Method 1: Add parameters to the method.
Method 2: Define a family of algorithms, encapsulate them (called "policies"), and then select an algorithm at run time.
Behavioral parameterization: Allow methods to accept multiple behaviors (or strategies) as parameters and use them internally to accomplish different behaviors.
Strategy Patternisa behavioral software design pattern This enables selecting an algorithm at runtime. The Strategy pattern
- Defines a family of algorithms,
- Encapsulates each algorithm, and
- Makes the algorithms interchangeable within that family.
Filter by abstract criteria
- Pass code/Behavior to method
- Multiple behaviors, one parameter.
You can use anonymous classes to reduce redundant code before Java8.
The behavior of the sort method can be parameterized with the Java.util.Comparator object.
You can use the Runnable interface to represent a block of code to execute (but not return any interfaces, void).
Java 8 Combat (note) Chapter II