中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

尋找哈爾濱網(wǎng)站建設(shè)市場營銷試題庫(帶答案)

尋找哈爾濱網(wǎng)站建設(shè),市場營銷試題庫(帶答案),wordpress 文章函數(shù),小米路由器wordpress19.命令模式 首先就是我們的 Client 想要實現(xiàn)一個功能,于是它就創(chuàng)建了一個 Command, 為了方便調(diào)用將 Command 封裝在了 Invoker 中,當(dāng)我們想調(diào)用的時候,Invoker 會執(zhí)行內(nèi)部 Command 提供的方法, Receiver 接收到 Command 的請求&a…

19.命令模式
首先就是我們的 Client 想要實現(xiàn)一個功能,于是它就創(chuàng)建了一個 Command, 為了方便調(diào)用將 Command 封裝在了 Invoker 中,當(dāng)我們想調(diào)用的時候,Invoker 會執(zhí)行內(nèi)部 Command 提供的方法, Receiver 接收到 Command 的請求,為其提供底部支持。

多說無益,我將通過一個例子介紹命令模式。

實例
目前大部分的軟件都支持用戶自定義界面,比如說我們可以修改字體大小,背景顏色等。我們就以此為例。首先,寫出兩個類。

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Font {private String fontSize = "normal";
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BackGround {private String bgColor = "default color";
}

這是 Command, 修改字體大小和背景的類都繼承于此。

public interface Command {void execute();
}

我們只是在類中獲得一個 Font 類的引用,然后調(diào)用setFontSize() 方法對字體的大小進(jìn)行設(shè)置。

@Data
@NoArgsConstructor
@AllArgsConstructor
public class LargeFontCommand implements Command {private Font font;@Overridepublic void execute() {font.setFontSize("large");}
}
@AllArgsConstructor
@NoArgsConstructor
@Data
public class NormalFontCommand implements Command {private Font font;@Overridepublic void execute() {font.setFontSize("Normal");}
}

background類的引用,調(diào)背景顏色

@NoArgsConstructor
@AllArgsConstructor
@Data
public class CustomBackGround implements Command {private BackGround backGround;private String color;public CustomBackGround(BackGround backGround){this.backGround = backGround;}@Overridepublic void execute() {backGround.setBgColor("Custom background");}
}
@AllArgsConstructor
@NoArgsConstructor
@Data
public class DefaultBackground implements Command {private BackGround backGround;@Overridepublic void execute() {backGround.setBgColor("default color");}
}

Invoker類存放命令

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Invoker {private List<Command> commands = new ArrayList<>();public void setCommand(int i,Command command){commands.add(i,command);}public void update(int i){commands.get(i).execute();}
}
public class CommandTest {public static void main(String[] args) {Font font = new Font();BackGround backGround = new BackGround();NormalFontCommand normalFontCommand = new NormalFontCommand(font);LargeFontCommand largeFontCommand = new LargeFontCommand(font);DefaultBackground defaultBackground = new DefaultBackground(backGround);CustomBackGround customBackGround = new CustomBackGround(backGround);Invoker invoker = new Invoker();invoker.setCommand(0,normalFontCommand);invoker.setCommand(1,largeFontCommand);invoker.setCommand(2,defaultBackground);invoker.setCommand(3,customBackGround);invoker.update(3);System.out.println(backGround.getBgColor());}
}

我們首先把所有的命令添加到了 Invoker , 然后直接調(diào)用 update() 方法就可以了。

這么做有什么好處呢?看的出來,可以將很多命令放進(jìn) Invoker , 它并不知道功能是如何實現(xiàn)的,它就像一個中介, Client 請求一個功能,它就將這個請求轉(zhuǎn)給 Command 去實現(xiàn)。這種模式有很多的用途,比如說多功能遙控器,日志打印等。

還有一點不得不說的,我們可以使用宏命令,什么是宏命令呢?就是寫一個 Command ,這個 Command 可以實現(xiàn)多個功能。比如說我們可以同時修改背景和顏色。

http://www.risenshineclean.com/news/66146.html

相關(guān)文章:

  • 做宣傳圖冊在什么網(wǎng)站浙江企業(yè)seo推廣
  • 自己做開獎網(wǎng)站seo外包方案
  • 阿里云做網(wǎng)站經(jīng)費(fèi)seo優(yōu)化網(wǎng)頁
  • 武漢做網(wǎng)站制作創(chuàng)建網(wǎng)站免費(fèi)注冊
  • 阿里云搭建自己的網(wǎng)站seo崗位是什么意思
  • smarty做網(wǎng)站百度圖片搜索引擎入口
  • 手機(jī)微網(wǎng)站建設(shè)方案網(wǎng)站怎么添加外鏈
  • 網(wǎng)站定向推送怎么做關(guān)鍵詞排名零芯互聯(lián)排名
  • 深圳個人外貿(mào)網(wǎng)站建排名優(yōu)化哪家好
  • 深圳建設(shè)局網(wǎng)站天津百度整站優(yōu)化服務(wù)
  • 網(wǎng)站右側(cè) 回到頂部站長工具流量統(tǒng)計
  • 仿站 做網(wǎng)站免費(fèi)推廣網(wǎng)站排行榜
  • 好用的日本ip地址seo優(yōu)化要做什么
  • 溫州網(wǎng)站推廣站建設(shè)全媒體廣告策劃營銷
  • 網(wǎng)站建設(shè)發(fā)票內(nèi)容蘇州網(wǎng)站制作開發(fā)公司
  • 惠州高端網(wǎng)站建設(shè)寵物美容師寵物美容培訓(xùn)學(xué)校
  • 如何建設(shè)網(wǎng)站平臺企業(yè)seo優(yōu)化服務(wù)
  • b2b網(wǎng)站怎么做濟(jì)南網(wǎng)站優(yōu)化
  • 工信部做網(wǎng)站認(rèn)證嗎杭州優(yōu)化公司多少錢
  • 企業(yè)做網(wǎng)站屬于廣告宣傳費(fèi)嗎sem投放
  • 天津網(wǎng)站建設(shè)交易公司網(wǎng)站建站要多少錢
  • 網(wǎng)站名稱備案青島神馬排名優(yōu)化
  • 山東公司網(wǎng)站開發(fā)外鏈工廠 外鏈
  • wordpress怎么導(dǎo)入自己的phpseo網(wǎng)站優(yōu)化外包
  • 自己做網(wǎng)站需要服務(wù)器嗎google付費(fèi)推廣
  • flash 網(wǎng)站頭部東莞做網(wǎng)站公司電話
  • wordpress 輪播圖插件下載惠州抖音seo
  • 網(wǎng)站 http 狀態(tài)碼返回值 301百度在線識圖查圖片
  • 怎么用自己的主機(jī)做網(wǎng)站服務(wù)器嗎企業(yè)宣傳片文案
  • 美國做ppt的網(wǎng)站有人百度看片嗎