The best aspect of the Strategy design pattern is its ability to allow change and adaptation. The design pattern is a virtual poster child for composition, where change and flexibility are handled with aplomb. Also, it's a great tool for working with algorithms large and small.
With any application, you're likely to encounter recurring algorithms. For this application, we decided to include some little algorithms that we use with different applications that have to be rebuilt every time we create an application that uses them. However, we don't want to make them into classes where the main objective is to inherit the functionality. Rather, we want to use them in composition so that we have more flexibility, and use their functionality only where we need them.
For our example, we've taken two simple types of string and sorting issues that seem to come up in a lot of different applications. First, we built some simple strategies for checking strings. The first strategy is designed to see if the @ symbol is placed in an e-mail address, and if it's not in the first or last position in a string. The second strategy is a password-checking algorithm that knocks all entries to lowercase, and then sees if they match the correct password.
Our second strategy interface is for demonstrating different sorting possibilities
Array class and
sort() method. By changing the sort parameters, you will be able to see which constants to use with different types of ...