六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

設(shè)計(jì)模式c#描述——裝飾(Decorator)模

[摘要]設(shè)計(jì)模式c#語(yǔ)言描述——裝飾(Decorator)模式 *本文參考了《JAVA與模式》的部分內(nèi)容,適合于設(shè)計(jì)模式的初學(xué)者。 裝飾模式又名包裝模式,以對(duì)客戶端透明的方式擴(kuò)展對(duì)象的功能,是繼承關(guān)系的一個(gè)替代方案。它使用原來被裝飾的類的一個(gè)子類的實(shí)例,把客戶端的調(diào)用委派到被裝飾類,客戶端并不會(huì)覺得對(duì)象在...
設(shè)計(jì)模式c#語(yǔ)言描述——裝飾(Decorator)模式



*本文參考了《JAVA與模式》的部分內(nèi)容,適合于設(shè)計(jì)模式的初學(xué)者。



裝飾模式又名包裝模式,以對(duì)客戶端透明的方式擴(kuò)展對(duì)象的功能,是繼承關(guān)系的一個(gè)替代方案。它使用原來被裝飾的類的一個(gè)子類的實(shí)例,把客戶端的調(diào)用委派到被裝飾類,客戶端并不會(huì)覺得對(duì)象在裝飾前和裝飾后有什么不同。在以下情況下應(yīng)使用裝飾模式:需要擴(kuò)展一個(gè)類的功能,或給一個(gè)類增加附加責(zé)任。動(dòng)態(tài)地給一個(gè)對(duì)象增加功能,這些功能可以再動(dòng)態(tài)地撤銷。需要增加由一些基本功能的排列組合而產(chǎn)生的非常大量的功能,從而使繼承關(guān)系變得不現(xiàn)實(shí)。



類圖如下所示:






裝飾模式包括如下角色:

抽象構(gòu)件(Component):給出一個(gè)抽象接口,以規(guī)范準(zhǔn)備接收附加責(zé)任的對(duì)象。

具體構(gòu)件(Concrete Component):定義一個(gè)將要接收附加責(zé)任的類。

裝飾(Decorator):持有一個(gè)構(gòu)件對(duì)象的實(shí)例,并定義一個(gè)與抽象構(gòu)件接口一致的接口。

具體裝飾(Concrete Decorator):負(fù)責(zé)給構(gòu)件對(duì)象“貼上”附加的責(zé)任。



Component:

public interface Component

{

void sampleOperation();

}// END INTERFACE DEFINITION Component



Decorator:

public class Decorator : Component

{

private Component component;



public Decorator(Component component)

{

this.component=component;

}



public virtual void sampleOperation()

{

component.sampleOperation();

}



}// END CLASS DEFINITION Decorator



ConcreteComponent:

public class ConcreteComponent : Component

{



public void sampleOperation()

{

Console.WriteLine ("ConcreteComponent sampleOperation");

}



}// END CLASS DEFINITION ConcreteComponent



ConcreteDecorator1:

public class ConcreteDecorator1 : Decorator

{



public ConcreteDecorator1(Component component):base(component)

{



}

override public void sampleOperation()

{

base.sampleOperation ();

Console.WriteLine ("ConcreteDecorator1 sampleOperation");

}



}// END CLASS DEFINITION ConcreteDecorator1



ConcreteDecorator2:

public class ConcreteDecorator2 : Decorator

{

public ConcreteDecorator2 (Component component):base(component)

{

}

override public void sampleOperation()

{

base.sampleOperation ();

Console.WriteLine ("ConcreteDecorator2 sampleOperation");

}



}// END CLASS DEFINITION ConcreteDecorator2



Client:

static void Main(string[] args)

{

Component component=new ConcreteComponent ();

Component concretedecorator1=new ConcreteDecorator1 (component); // 包裝

Component concretedecorator2=new ConcreteDecorator2 (concretedecorator1);



concretedecorator2.sampleOperation ();

}



程序輸出如下:

ConcreteComponent sampleOperation

ConcreteDecorator1 sampleOperation

ConcreteDecorator2 sampleOperation



主站蜘蛛池模板: 日本久久免费大片 | 亚洲欧美日韩高清一区二区三区 | 在线免费观看日本 | 色综合成人丁香 | 囗交交性网免费 | 亚洲国产成人久久 | 性色视频在线观看 | 日韩精品免费一线在线观看 | 日产国产精品久久久久久 | 四虎永久在线精品国产馆v视影院 | 亚洲精品乱码久久久久久中文字幕 | 五月天色网址 | 一区二区三区精品视频 | 色综合久久综合 | 日本成人xxx | 欧美一级特黄一片免费 | 亚洲伊人久久大香线蕉啊 | 四虎国产精品免费五月天 | 亚洲天堂男人在线 | 亚洲狼网站狼狼鲁亚洲下载 | 忘忧草一区 | 中文字幕日韩精品一区口 | 四虎影院在线网址 | 亚洲欧美日韩国产精品影院 | 欧美一区日韩一区中文字幕页 | 亚洲国产成人久久一区二区三区 | 日本视频在线观看免费 | 一本久道久久综合多人 | 性xxxxx大片免费视频 | 青青青亚洲精品国产 | 亚洲高清自拍 | 日韩高清中文字幕 | 性调教视频 | 四虎免费在线播放 | 亚欧精品在线观看 | 色欧美色| 日韩高清在线日韩大片观看网址 | 青草五月天 | 色天天综合色天天天天看大 | 香蕉视频久久 | 日本aⅴ永久免费网站www |