Skip to main content
Post Undeleted by Caleth
Post Deleted by Caleth
added 178 characters in body
Source Link
Caleth
  • 12.4k
  • 2
  • 29
  • 45

The point of the strategy pattern is to isolate the choice of what to do from the doing of it. Let's say you have a UI with a pair of dropdowns, InputType and OutputType, and a button DoConversion.

You can have UI code like

partial class UI { public Converter { get; set; } void onInputTypeCombo_Changed(InputType inputType) { Converter.setInputStrategy(inputType); } void onOutputTypeCombo_Changed(OutputType outputType) { Converter.setOutputStrategy(outputType); } void onDoConversion_Clicked() { Converter.doConversion(); } }; 

And the Converter will instantiate concrete strategy objects based on the passed InputType and OutputType. But it won't do the conversion until the button is pressed.

The point of the strategy pattern is to isolate the choice of what to do from the doing of it. Let's say you have a UI with a pair of dropdowns, InputType and OutputType, and a button DoConversion.

You can have UI code like

partial class UI { public Converter { get; set; } void onInputTypeCombo_Changed(InputType inputType) { Converter.setInputStrategy(inputType); } void onOutputTypeCombo_Changed(OutputType outputType) { Converter.setOutputStrategy(outputType); } void onDoConversion_Clicked() { Converter.doConversion(); } }; 

The point of the strategy pattern is to isolate the choice of what to do from the doing of it. Let's say you have a UI with a pair of dropdowns, InputType and OutputType, and a button DoConversion.

You can have UI code like

partial class UI { public Converter { get; set; } void onInputTypeCombo_Changed(InputType inputType) { Converter.setInputStrategy(inputType); } void onOutputTypeCombo_Changed(OutputType outputType) { Converter.setOutputStrategy(outputType); } void onDoConversion_Clicked() { Converter.doConversion(); } }; 

And the Converter will instantiate concrete strategy objects based on the passed InputType and OutputType. But it won't do the conversion until the button is pressed.

Source Link
Caleth
  • 12.4k
  • 2
  • 29
  • 45

The point of the strategy pattern is to isolate the choice of what to do from the doing of it. Let's say you have a UI with a pair of dropdowns, InputType and OutputType, and a button DoConversion.

You can have UI code like

partial class UI { public Converter { get; set; } void onInputTypeCombo_Changed(InputType inputType) { Converter.setInputStrategy(inputType); } void onOutputTypeCombo_Changed(OutputType outputType) { Converter.setOutputStrategy(outputType); } void onDoConversion_Clicked() { Converter.doConversion(); } };