by ptr · 5y ago · 0 comments
Regarding the strategy pattern, when does it start becoming the pattern and when is it just "passing a function as a parameter"?
sortList(list, [](const item& i) {return i.name();});
struct MySorter
{
bool operator ()(const item&) {...}
};
sortList(list, MySorter{});
class MySorter : public ISorter
{
public:
virtual bool execute(const item&) override {...}
};
sortList(list, MySorter{});So yes, there are trivial things which you can argue the toss on, but in the last month I've used HTTP libraries that don't allow you to supply a strategy for retry logic and machine learning libraries that don't allow a strategy for early stopping.