CSC/ECE 517 Fall 2010/ch3 3h PW

From Expertiza_Wiki
Revision as of 23:17, 5 October 2010 by Phwetsel (talk | contribs)
Jump to navigation Jump to search

The Strategy pattern in static and dynamic languages

What is the Strategy Pattern

The main purpose of the strategy pattern is to separate out an object and how it behaves into two different classes. The first advantage for doing this is so that if an object can have different behaviors then it is easy to manage them in their own classes. Secondly, if a certain type of behavior need to be changed, it only need to be changed in that behavior class rather than in multiple classes if there were multiple objects that had this behavior.

How to Implement in a Static Language

Example

Java Code

How to Implement in a Dynamic Language

Examples

Ruby code