I implemented the Strategic Template the other day, it is used to encapsulate methods, which you can swap at runtime. Like the Command Pattern, but more untied.
This is how I used it. I had to send files to third parties, and I had several choices: I had FTP, SFTP, FTPS and SMB.
Interface:
interface ITransferStrategry { void TransferFiles(System.Collections.Generic.IList<string> files); }
Implementation:
public class FTPTransfer : ITransferStrategry { public void TransferFiles(IList<string> files) {
Context:
public class TransferContext { private ITransferStrategry _strategy; public TransferContext(ITransferStrategry strategy) { this._strategy = strategy; } public void Send(IList<string> files) { this._strategy.TransferFiles(files); } }
Client:
public void Client() { TransferContext context = new TransferContext(new FTPTransfer()); context.Send(files); }
It is quite easy and simple to maintain. Hope this helps someone.
source share