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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CERT Recently Published Vulnerability Notes
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
Security Latest
Security Latest
P
Privacy International News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
S
Secure Thoughts
PCI Perspectives
PCI Perspectives
Simon Willison's Weblog
Simon Willison's Weblog
D
DataBreaches.Net
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
罗磊的独立博客
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
V
V2EX
Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tenable Blog
T
Threat Research - Cisco Blogs
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
Lohrmann on Cybersecurity
F
Full Disclosure
H
Help Net Security
博客园 - Franky
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
Engineering at Meta
Engineering at Meta
A
Arctic Wolf
O
OpenAI News
S
Securelist

博客园 - tf.li

清理MVC4 Internaet 项目模板清理 SQL2014 尝试读取或写入受保护的内存。这通常指示其他内存已损坏 nodejs 环境配置技巧 mongdb window 服务安装批处理 bower 安装后 jade 引用404问题 我的Prototype模式框架 转自CnBeta 令人深思 [译稿]为什么我们不要 .NET 程序员 JSON.NET、WebService与JQuery协同工作 我修改的IP地址掩码 呵呵~~开心 Ext.Ajax.request 传值问题 从小做大之一---------一切从建模开始 [求助]关于文本行转列的疑问~~ To Terrylee 我的设计模型之小议工厂模式 我对线程池的一点理解 面向接口编程之惑 第二版 面向接口编程之惑 我的设计模型之适配器模式 我的设计模型之简单工厂
我的设计模型之装饰者模式
tf.li · 2008-07-30 · via 博客园 - tf.li

今天听了webcast的C#设计模型 感觉更好了,因为之前看过《小菜与大鸟不得不说的事》今天温习一下感觉装饰者模式真的很爽啊好了 废话少说 放代码

Code

此为抽象类,是抽象的哦。

   class T50:Tank
    {
        
public override void Shot()
        {
            Console.WriteLine(
"我是T50坦克");
        }
public override void Run()
        {
            Console.WriteLine(
"我可走正常的路");
        }
    }

一个实体类继承自抽象

下面轮到我们的主角装饰者类上场了

    class JiaNongPo:Tank
    
{
        
private Tank tank;
        
public JiaNongPo(Tank tank)
        
{
            
this.tank = tank;
        }

        
public override void Shot()
        
{
            Console.WriteLine(
"装备加农炮");
        }

        
public override void Run()
        
{
            tank.Run();
        }

    }

    
class Papo : Tank
    
{
        
private Tank tank;
        
public Papo(Tank tank)
        
{
            
this.tank = tank;
        }

        
public override void Run()
        
{
            Console.WriteLine(
"装备爬坡器!");
        }

        
public override void Shot()
        
{
            tank.Shot();
        }


    }

这是我们的装饰者类,之前用过另外一个抽象装饰者类来继承Tank类 后来发现状态保存比较麻烦,所以不用了 直接用

具体的装饰者来继承但是一个缺点就是当Tank类中的方法较多的时候会要求全部重载 Tank类的方法比较麻烦啊,不知各位有什么好的解决办法。好了天不早了 我要休息了啊 努力中....