Closed archatas closed 6 years ago
Hey, I meant you can decide and pick any strategy based on the application logic. It has nothing to do with the pattern.
Here you go with the conditional
$dataset = [1, 5, 4, 3, 2, 8];
$strategy = count($dataset > 100) ? new QuickSortStrategy() : new BubbleSortStrategy();
$sorter = new Sorter($strategy);
$sorter->sort($dataset);
I've read your writing about the patterns. Great work indeed!
I just have a question about the strategy pattern. In the description, you say, that it allows to choose an algorithm based on some conditions, but in the code example there is no condition checking. Is it incomplete, or is it not part of the pattern itself?