Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Strategy Pattern, can't we make each strategy as a function but not as a class?

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?

like image 467
nonopolarity Avatar asked Jun 08 '09 09:06

nonopolarity


1 Answers

Depends on the language. In C#, you could make it a delegate. In Java, it would rather be a anonymous class. In C++, you could really make it a function pointer.

like image 199
Erich Kitzmueller Avatar answered Nov 06 '22 04:11

Erich Kitzmueller