亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? decoratorpattern.htm

?? 程式設(shè)計(jì)是思維具體化的一種方式
?? HTM
字號(hào):
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>



  
  
  
  <link rel="stylesheet" href="css/stdlayout.css" type="text/css">



  
  
  
  <link rel="stylesheet" href="css/print.css" type="text/css">



  
  
  
  <meta content="text/html; charset=gb2312" http-equiv="content-type">



  
  
  
  <title>Decorator 模式</title>
</head>


<body>



<h3><a href="http://caterpillar.onlyfun.net/GossipCN/index.html">From
Gossip@caterpillar</a></h3>



<h1><a href="CppGossip.html">Design Pattern: Decorator 模式</a></h1>



在Java
Swing中的JTextArea元件預(yù)設(shè)并沒(méi)有卷軸,因?yàn)樵O(shè)計(jì)人員認(rèn)為卷軸的功能并不是一定需要的,而決定讓程式人員可以動(dòng)態(tài)選擇是否增加卷軸功能,卷
軸的功能是由JScrollPane元件提供,如果您要加入一個(gè)具有卷軸功能的JTextArea,您可以如下進(jìn)行設(shè)計(jì):<br>
<div style="margin-left: 40px;"><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">JTextArea textArea = new JTextArea();</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">JScrollPane scrollPane = new JScrollPane(textArea);</span><br>
</div>
&nbsp;<br>
JScrollPane對(duì)JTextArea即是個(gè)容器,而它對(duì)JFrame來(lái)說(shuō)又是個(gè)元件,可以如下這般將之加入JFrame中:<br>
<div style="margin-left: 40px;"><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">getContentPane().add(scrollPane);</span><br>
</div>
&nbsp;<br>
像這樣動(dòng)態(tài)的為JTextArea加入功能的方法,我們可以使用Decorator模式來(lái)組織結(jié)構(gòu),您可以動(dòng)態(tài)的為一個(gè)物件加入一些功能(像是為
JTextArea加上卷軸),而又不用修改JTextArea的功能。對(duì)JTextArea來(lái)說(shuō),JScrollPane就好像是一個(gè)卷軸外框,直接套
在JTextArea上作裝飾,就好比您在照片上加上一個(gè)相框的意思。<br>
<br>
先以上面這個(gè)例子來(lái)說(shuō)明Decorator模式的一個(gè)實(shí)例:<br>

<div style="text-align: center;"><img style="width: 455px; height: 255px;" alt="Decorator" title="Decorator" src="images/decorator-1.jpg"><br>
</div>
<br>
如上圖所示的,無(wú)論是TextView或是Decorator類別,它們都是VisualComponent的一個(gè)子類,也就是說(shuō)它們都是一個(gè)可視元件,
而Decorator類又聚合了VisualComponent,所以又可以當(dāng)作TextView容器,ScrollDecorator類別實(shí)作了
Decorator類,它可能是這樣設(shè)計(jì)的:<br>
<div style="margin-left: 40px;"><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">public abstract class Decorator extends VisualComponent {</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; protected VisualComponent component;</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; public Decorator(VisualComponent component) {</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.component = component;</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; public void draw() {</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; component.draw();</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">}</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">public class ScrollDecorator extends Decorator {</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; public ScrollDecorator(VisualComponent component) {</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super(component);</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; public void draw() {</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super.draw();</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scrollTo();</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; public void scrollTo() {</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ....</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">}</span><br>
</div>
&nbsp;<br>
要將新功能套用至TextView上,可以這樣設(shè)計(jì):<br>
<div style="margin-left: 40px;"><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">ScrollDecorator scrollDecorator = </span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
new ScrollDecorator(new TextView());</span><br>
</div>
&nbsp;<br>
super.draw()會(huì)先呼叫component也就是TextView物件的draw()方法先繪制TextView,然后再進(jìn)行
ScrollPanel的scrollTo(),也就是卷動(dòng)的方法。在圖中也表示了一個(gè)BorderDecorator,它可能是這樣設(shè)計(jì)的:<br>
<div style="margin-left: 40px;"><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">public class BorderDecorator extends Decorator {</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; public BorderDecorator(VisualComponent component) {</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super(component);</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; public void draw() {</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super.draw();</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; drawBorder();</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; public void drawBorder() {</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ....</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">}</span><br>
</div>
&nbsp;<br>
要將ScrollDecorator與BorderDecorator加至TextView上,我們可以這樣設(shè)計(jì):<br>
<div style="margin-left: 40px;"><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">BorderDecorator borderDecorator =</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new BorderDecorator(</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new ScrollDecorator(new TextView()));</span><span style="font-weight: bold; font-family: Courier New,Courier,monospace;"></span><br>
</div>
<br>
所以當(dāng)BorderDecorator調(diào)用draw()方法時(shí),它會(huì)先調(diào)用ScrollDecorator的draw()方法,而 ScrollDecorator的draw()方法又會(huì)先調(diào)用TextView的draw()方法,所以繪制的順序變成:<br>
<div style="margin-left: 40px;"><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">TextDraw.draw();</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">ScrollDecorator.scrollTo();</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;">BorderDecorator.drawBorder();</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;">
<span style="font-weight: bold; font-family: Courier New,Courier,monospace;"></span><br>
</div>
下圖為物件之間的調(diào)用關(guān)系:<br>
<div style="text-align: center;"><img style="width: 403px; height: 71px;" alt="Decorator" title="Decorator" src="images/decorator-2.jpg"><br>
</div>
<br>
Decorator模式的 UML 結(jié)構(gòu)圖如下所示:<br>
<div style="text-align: center;"><img style="width: 486px; height: 259px;" alt="Decorator" title="Decorator" src="images/decorator-3.jpg"><br>
</div>
<br>
在Gof的書(shū)中指出另一個(gè)范例,它設(shè)計(jì)一個(gè)Stream抽象類,而有一個(gè)StreamDecorator類,Stream的子類有處理記憶體串流的
MemoryStream與FileStream,有各種方法可以處理串流,也許只是單純的處理字元,也許會(huì)進(jìn)行壓縮,也許會(huì)進(jìn)行字元轉(zhuǎn)換,最基本的處理
可能是處理字元,而字元壓縮被視為額外的功能,這個(gè)時(shí)候我們可以使用裝飾模式,在需要的時(shí)候?yàn)镾tream物件加上必要的功能,事實(shí)上在java.io中
的許多輸入輸出物件,就是采取這樣的設(shè)計(jì)。<br>
<br>



</body>
</html>

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲欧美激情插| 国产精品不卡一区| 国产宾馆实践打屁股91| 久久精品人人做| 91国偷自产一区二区使用方法| 亚洲国产一区二区三区 | 性做久久久久久| 欧美大片在线观看| 懂色av一区二区三区免费观看| 一个色在线综合| 精品国产伦理网| gogogo免费视频观看亚洲一| 亚洲视频小说图片| 精品国产sm最大网站免费看| 99久久久久久99| 国产精品18久久久久久久久久久久| 亚洲午夜影视影院在线观看| 国产精品色哟哟网站| 日韩欧美成人激情| 69久久夜色精品国产69蝌蚪网| 91黄色免费网站| 日本高清不卡在线观看| 成人免费av资源| 国产一区二区三区精品视频| 日本中文字幕一区| 一区二区三区中文字幕| 亚洲激情中文1区| 成人欧美一区二区三区视频网页| 久久久久成人黄色影片| 日韩一级二级三级精品视频| 欧美日韩一级大片网址| 色婷婷久久久综合中文字幕| 成人激情视频网站| av中文字幕不卡| 成人免费精品视频| 91在线观看美女| 99久久国产免费看| 在线观看视频91| 色天使久久综合网天天| 成人午夜在线免费| 91亚洲男人天堂| 日本韩国一区二区三区视频| 69堂成人精品免费视频| 亚洲国产高清不卡| 亚洲欧美国产高清| 免费观看91视频大全| 国产成人av电影在线观看| 色域天天综合网| 91精品在线一区二区| 久久婷婷国产综合精品青草| 日产精品久久久久久久性色| 国产精品一卡二卡| 欧美精三区欧美精三区| 国产日产欧美一区二区三区| 午夜欧美电影在线观看| 精久久久久久久久久久| 欧美视频日韩视频在线观看| 久久青草欧美一区二区三区| 亚洲美女视频在线观看| 日本欧美一区二区在线观看| 成人一区在线观看| 日韩欧美精品在线视频| 亚洲裸体xxx| 国产精选一区二区三区| 欧美日韩精品一区二区| 精品人在线二区三区| 一区二区三区精品视频在线| 99久久久国产精品免费蜜臀| 国产欧美日韩精品一区| 国产在线播放一区三区四| 欧美一区二区精美| 日韩精品国产欧美| 欧美精品xxxxbbbb| 亚洲图片一区二区| 欧美视频在线一区| 亚洲精品视频一区二区| 国产一区激情在线| 日韩一区二区三区视频在线| 一区二区理论电影在线观看| 国产mv日韩mv欧美| 久久综合久久99| 国产精品一区二区x88av| 国产精品色在线观看| 91看片淫黄大片一级在线观看| 国产精品久久久久四虎| 97成人超碰视| 亚洲国产另类精品专区| 欧美精品乱码久久久久久| 日本亚洲一区二区| 久久久国际精品| zzijzzij亚洲日本少妇熟睡| 自拍偷拍亚洲欧美日韩| 欧美系列在线观看| 亚洲国产另类精品专区| 3751色影院一区二区三区| 乱一区二区av| 中文无字幕一区二区三区| 欧美人妖巨大在线| 亚洲一区影音先锋| 91丨porny丨首页| 亚洲卡通欧美制服中文| 91精品国产欧美一区二区18| 国产精品美女视频| 欧美视频第二页| 国产精品 欧美精品| 亚洲综合偷拍欧美一区色| 国产日韩欧美精品一区| 欧美日韩视频第一区| 成人动漫视频在线| 韩国一区二区三区| 亚洲国产精品久久不卡毛片| 国产清纯白嫩初高生在线观看91| 欧美色区777第一页| 国产精品主播直播| 日本欧美一区二区| 日韩高清一区在线| 欧美国产一区二区| 欧美中文字幕亚洲一区二区va在线| 国产一区免费电影| 亚洲国产一二三| 亚洲欧洲av另类| 久久综合中文字幕| 3d动漫精品啪啪一区二区竹菊| 成人精品视频.| 免费不卡在线视频| 夜夜爽夜夜爽精品视频| 欧美国产精品v| 久久噜噜亚洲综合| 日韩美女视频在线| 91极品美女在线| 精品污污网站免费看| 在线精品亚洲一区二区不卡| 欧美在线视频日韩| 欧美精品丝袜久久久中文字幕| 在线观看亚洲a| 欧美视频中文一区二区三区在线观看| 在线视频一区二区三| 欧美色视频在线| 在线不卡中文字幕播放| 7777精品伊人久久久大香线蕉最新版| va亚洲va日韩不卡在线观看| 粉嫩高潮美女一区二区三区| 国产99久久久精品| 国产麻豆成人传媒免费观看| 成人国产电影网| 色偷偷88欧美精品久久久| 欧美日韩综合在线| 91精品综合久久久久久| 欧美精品一区二区三区久久久| 久久久影视传媒| 亚洲精品精品亚洲| 美国精品在线观看| 成人免费视频一区二区| 色94色欧美sute亚洲线路一久| 欧美麻豆精品久久久久久| 日韩视频在线观看一区二区| 精品久久99ma| 国产精品区一区二区三| 亚洲精品老司机| 秋霞电影一区二区| 福利一区福利二区| 欧美四级电影网| 精品999在线播放| 国产精品久久777777| 日韩精品三区四区| 懂色一区二区三区免费观看 | 在线观看日韩国产| 久久久精品免费网站| 精品一区二区综合| 欧美另类变人与禽xxxxx| 中文幕一区二区三区久久蜜桃| 久久99精品久久久久| 日韩一区二区精品| 日韩va亚洲va欧美va久久| 99re在线视频这里只有精品| 久久色中文字幕| 亚洲chinese男男1069| av爱爱亚洲一区| 精品福利在线导航| 亚洲r级在线视频| 成人午夜免费av| 亚洲精品一线二线三线无人区| 亚洲国产精品一区二区久久恐怖片| 美女免费视频一区| 欧美视频在线播放| 亚洲午夜精品在线| 在线观看成人小视频| 日韩理论电影院| 99久久伊人精品| 中文字幕免费观看一区| 成人不卡免费av| 亚洲九九爱视频| 欧美日韩一区二区不卡| 丝袜脚交一区二区| 欧美一区二区视频在线观看2022 | 26uuu精品一区二区| 欧美a级理论片| 久久久久国产一区二区三区四区 | 久久久99精品免费观看| 免费成人在线影院|