惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Tor Project blog
AWS News Blog
AWS News Blog
量子位
博客园 - 聂微东
L
LINUX DO - 热门话题
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
小众软件
小众软件
人人都是产品经理
人人都是产品经理
A
About on SuperTechFans
L
Lohrmann on Cybersecurity
Know Your Adversary
Know Your Adversary
V
Visual Studio Blog
P
Privacy International News Feed
K
Kaspersky official blog
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
G
GRAHAM CLULEY
S
Securelist
Last Week in AI
Last Week in AI
Latest news
Latest news
B
Blog
T
Tenable Blog
Cisco Talos Blog
Cisco Talos Blog
宝玉的分享
宝玉的分享
T
The Exploit Database - CXSecurity.com
N
Netflix TechBlog - Medium
A
Arctic Wolf
SecWiki News
SecWiki News
C
Cisco Blogs
月光博客
月光博客
PCI Perspectives
PCI Perspectives
Cloudbric
Cloudbric
H
Hacker News: Front Page
F
Full Disclosure
TaoSecurity Blog
TaoSecurity Blog
V2EX - 技术
V2EX - 技术
The Last Watchdog
The Last Watchdog
S
Schneier on Security
罗磊的独立博客
S
Security Affairs
Scott Helme
Scott Helme
P
Proofpoint News Feed
GbyAI
GbyAI
Google Online Security Blog
Google Online Security Blog
The Register - Security
The Register - Security
W
WeLiveSecurity
Hugging Face - Blog
Hugging Face - Blog
博客园 - 叶小钗

博客园 - love .net FrameWork

SQL Server 2005 中的分区表和索引应用 Windows Forms 分页控件 WPF 插件开发(.NET Framework 3.5 System.Addin) 一生回味的100句凡人语录 经典短句 一生中必看的30个故事 别人看不懂的悲伤 Most of the 10 classic love sentence 5月28日 《魔兽争霸3》微操作基础教程 数据访问抽象基础类 无法将类型“ASP.login_aspx”转换为“System.Web.UI.WebControls.Login” - love .net FrameWork 看到一很好的SQL代码 拼接sql语句 关于ibatis.net框架(NPetshop学习) Factory Method 工厂方法模式(创建型模式) SQL各种日期转换代码大全 在ASP.NET中使用Session常见问题集锦(转) Sys.ArgumentOutOfRangeException: Value must be an integer - love .net FrameWork
Stratrgy 策略模式
love .net FrameWork · 2008-03-03 · via 博客园 - love .net FrameWork

      定义一系列的算法,把他们一个一个的封装起来,并使它们可以相互替换。该模式使得算法可独立使用它的客户而变换。
                                                                                                                  ——《设计模式》GOF

     Stratrgy应用比较广泛,比如,有一个文件,要实现生成两种不同字体的文件,这取决于用户的要求,所以我们要准备几套变量字符替代方案.

先在IDAL层定义一个接口来表示生成文件的方法:

public interface IStrategy
    {
        
void FileType(string Types);
    }

实现接口:

 class StrategyFanti : IStrategy
    {
        
public void FileType(string Types)
        {
            Console.WriteLine(
"繁体文件:{0}", Types);
        }
    }
class StrategyZhongwen : IStrategy
    {
        
public void FileType(string Types)
        {
            Console.WriteLine(
"简体文件{0}", Types);
        }
    }

定义实现方法:

public class Solve
    {
        IStrategy _strategy 
= null;
        
public Solve(IStrategy strategy)
        {
            
this._strategy = strategy;
        }
public void Type(string Types)
        {
            _strategy.FileType(Types);
        }
    }

调用:

 class Program
    {
        
static void Main(string[] args)
        {
            Solve so 
= new Solve(new StrategyFanti());
            so.Type(
"策略模式");
        }
    }