Strategy pattern - The strategy pattern (also known as the policy pattern) is a software design pattern, whereby an algorithm's behavior can be selected at run time. Formally speaking, the strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
In the pseudo-code example below, the Command pattern sets the parameters and sql for each unique run. What is actually run at run time is determined organically. [workflow].[run] executes each <sql> object that it is passed with no knowledge of the actual implementation.</sql>
Command pattern using [xml]
- command object
- receiver object
declare @command [xml] =
N'<command>
<receiver>
<parameters>@output [xml] output</parameters>
<sql>select @output = (<select statement>
for xml path(output'), root(N'output_tree'));</sql>
</receiver>
</command>';
Setter / Run
- invoker object
declare procedure [workflow].[run] @workflow [xml], @output [xml] output
as
if (@workflow is not null)
execute sp_execute
@sql=@workflow.value(N'(/command/receiver/sql/text())[1]',
N'[nvarchar](max)'),
@parameters=@workflow.value(
N'(/command/receiver/parameters/text())[1]', N'[nvarchar](max)'),
@output=@output output;
go
copyright Katherine Elizabeth Lightsey 1959-2013 (aka; my life)
"Always forgive your enemies; nothing annoys them so much." - Oscar Wilde