In the usual Strategy Pattern, we make each strategy as a class. Can’t we make it a function, and just assign the reference to the function when we instantiate an object, and let the object call that function?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In the simplest cases, you can replace Strategy patterns with a function pointer. However, consider this case
If we just gave a simple function pointer, things start getting really hairy because you can no longer refactor that thing (well, at least not in an well encapsulated way).