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

推荐订阅源

PCI Perspectives
PCI Perspectives
AI
AI
L
LINUX DO - 最新话题
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
T
Troy Hunt's Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Forbes - Security
Forbes - Security
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
O
OpenAI News
D
DataBreaches.Net
S
Secure Thoughts
SecWiki News
SecWiki News
L
LangChain Blog
Google DeepMind News
Google DeepMind News
博客园 - 【当耐特】
Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
有赞技术团队
有赞技术团队
The Last Watchdog
The Last Watchdog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
宝玉的分享
宝玉的分享
N
News | PayPal Newsroom
博客园 - 聂微东
TaoSecurity Blog
TaoSecurity Blog
Cloudbric
Cloudbric
Blog — PlanetScale
Blog — PlanetScale
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
量子位
T
Threatpost
Security Latest
Security Latest
P
Privacy & Cybersecurity Law Blog
GbyAI
GbyAI
博客园 - 叶小钗
L
Lohrmann on Cybersecurity
S
Security @ Cisco Blogs
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Tailwind CSS Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
L
LINUX DO - 热门话题

博客园 - 走到天亮

设计模式之“适配器模式” 设计模式之“门面模式” 设计模式之“抽象工厂模式” 设计模式之“单例模式” 设计模式之“代理模式” 《C# to IL》第三章 选择和循环 《C# to IL》第二章 IL基础 《C# to IL》第一章 IL入门 淘宝下单高并发解决方案(转载) java linux 配置环境 Spring Aop之(二)--Aop 切面声明和通知 Spring aop Spring RegexpMethodPointcutAdvisor和NameMatchMethodPointcutAdvisor Spring BeanNameAutoProxyCreator 与 ProxyFactoryBean CentOS的IP配置专题 Spring Bean属性绑定Bean返回值 【阿里的感悟】质量该如何做? .(转载) Ubuntu开机自动启动script(2) Ubuntu开机自动启动Script
设计模式之“策略模式”
走到天亮 · 2013-07-17 · via 博客园 - 走到天亮

策略模式:
策略模式定义了一系列算法,把它们一个个封装起来,并且使它们可相互替换。该模式可使得算法能独立于使用它的客户而变化。

通用类图:

实例:

商品折扣计算

 class Program
    {
        static void Main(string[] args)
        {
            ShopCart sc = new ShopCart(new ProudctA());
            sc.doSomthing();
            sc = new ShopCart(new ProudctB());
            sc.doSomthing();
        }
    }
    public class ShopCart {
        public IStrategy strategr;
        public ShopCart(IStrategy strategr) {
            this.strategr = strategr;
        }
        public void doSomthing()
        {
            this.strategr.compute();
        }
    }
    public interface IStrategy
    {

         void compute();
    }
    public class ProudctA : IStrategy {

        public void compute()
        {
            Console.WriteLine("商品折扣价100");
        }
    }
    public class ProudctB: IStrategy
    {

        public void compute()
        {
            Console.WriteLine("商品折扣价200");
        }
    }