摘要:時(shí)間年月日星期二說(shuō)明本文部分內(nèi)容均來(lái)自慕課網(wǎng)。慕課網(wǎng)教學(xué)源碼學(xué)習(xí)源碼第一章觀察者模式概述課程簡(jiǎn)介觀察者模式的定義定義對(duì)象間的一種一對(duì)多的依賴關(guān)系。
時(shí)間:2017年08月29日星期二
說(shuō)明:本文部分內(nèi)容均來(lái)自慕課網(wǎng)。@慕課網(wǎng):http://www.imooc.com
教學(xué)源碼:https://github.com/zccodere/s...
學(xué)習(xí)源碼:https://github.com/zccodere/s...
觀察者模式的定義
定義對(duì)象間的一種一對(duì)多的依賴關(guān)系。當(dāng)一個(gè)對(duì)象的狀態(tài)發(fā)生改變時(shí),所有依賴于它的對(duì)象都得到通知并被自動(dòng)更新。
案例流程圖
第二章:觀察者模式實(shí)戰(zhàn) 2-1 結(jié)構(gòu)類圖觀察者模式結(jié)構(gòu)
觀察者模式類圖
2-2 通用代碼實(shí)現(xiàn)步驟
1.目標(biāo)對(duì)象的定義 2.具體的目標(biāo)對(duì)象的定義 3.觀察者的接口定義 4.觀察者的具體實(shí)現(xiàn)
代碼編寫(xiě)
1.編寫(xiě)Subject類
package com.myimooc.designpattern.c5observer.common; import java.util.ArrayList; import java.util.List; /** * @describe 目標(biāo)類,目標(biāo)對(duì)象,它知道觀察它的觀察者,并提供注冊(cè)(添加)和刪除觀察者的接口 * @author zc * @version 1.0 2017-08-29 */ public class Subject { /** * 用來(lái)保證注冊(cè)的觀察者對(duì)象 */ private Listobservers = new ArrayList (); /** * 增加觀察者 */ public void attach(Observer observer){ observers.add(observer); } /** * 刪除指定的觀察者 */ public void detach(Observer observer){ observers.remove(observer); } /** * 通過(guò)所有注冊(cè)的觀察者對(duì)象 */ protected void notifyObserver() { observers.forEach(observer ->{ observer.update(this); }); } }
2.編寫(xiě)ConcreteSubject類
package com.myimooc.designpattern.c5observer.common; /** * @describe 具體的目標(biāo)對(duì)象,負(fù)責(zé)把有關(guān)狀態(tài)存入到相應(yīng)的觀察者對(duì)象中 * @author zc * @version 1.0 2017-08-29 */ public class ConcreteSubject extends Subject { /** * 目標(biāo)對(duì)象的狀態(tài) */ private String subjectState; public String getSubjectState() { return subjectState; } public void setSubjectState(String subjectState) { this.subjectState = subjectState; // 當(dāng)狀態(tài)發(fā)生改變時(shí),通知觀察者 this.notifyObserver(); } }
3.編寫(xiě)Observer類
package com.myimooc.designpattern.c5observer.common; /** * @describe 觀察者接口,定義一個(gè)更新的接口給那些在目標(biāo)對(duì)象發(fā)生改變的時(shí)候被通知的對(duì)象 * @author zc * @version 1.0 2017-08-29 */ public interface Observer { /** * 更新的接口 * @param subject 傳入的目標(biāo)對(duì)象,方便獲取相應(yīng)的目標(biāo)對(duì)象的狀態(tài) */ void update(Subject subject); }
4.編寫(xiě)ConcreteObserver類
package com.myimooc.designpattern.c5observer.common; /** * @describe 具體的觀察者對(duì)象,實(shí)現(xiàn)更新的方法,使自身的狀態(tài)和目標(biāo)的狀態(tài)保持一致 * @author zc * @version 1.0 2017-08-29 */ public class ConcreteObserver implements Observer { /** * 觀察者的狀態(tài) */ private String observerState; /** * 獲取目標(biāo)類的狀態(tài)同步到觀察者的狀態(tài)中 */ @Override public void update(Subject subject) { observerState = ((ConcreteSubject)subject).getSubjectState(); } public String getObserverState() { return observerState; } }2-3 訂閱天氣
代碼編寫(xiě)
1.編寫(xiě)WeatherSubject類
package com.myimooc.designpattern.c5observer.weather; import java.util.ArrayList; import java.util.List; /** * @describe 管理訂閱者列表 * @author zc * @version 1.0 2017-08-29 */ public class WeatherSubject { /** * 訂閱者列表 */ private Listobservers = new ArrayList (); /** * 把訂閱天氣的人增加到訂閱者列表中 */ public void attach(Observer observer){ observers.add(observer); } /** * 刪除訂閱的人 */ public void detach(Observer observer){ observers.remove(observer); } /** * 通知所有已經(jīng)訂閱天氣的人 */ protected void notifyObserver() { observers.forEach(observer ->{ observer.update(this); }); } }
2.編寫(xiě)ConcreteWeatherSubject類
package com.myimooc.designpattern.c5observer.weather; /** * @describe 具體的目標(biāo)對(duì)象,負(fù)責(zé)把有關(guān)狀態(tài)存入到相應(yīng)的觀察者對(duì)象中 * @author zc * @version 1.0 2017-08-29 */ public class ConcreteWeatherSubject extends WeatherSubject { /** * 獲取天氣的內(nèi)容信息 */ private String weatherContent; public String getWeatherContent() { return weatherContent; } public void setWeatherContent(String weatherContent) { this.weatherContent = weatherContent; // 內(nèi)容有了,說(shuō)明天氣更新了,通知所有訂閱的人 this.notifyObserver(); } }
3.編寫(xiě)Observer類
package com.myimooc.designpattern.c5observer.weather; /** * @describe 觀察者接口,定義一個(gè)更新的接口給那些在目標(biāo)對(duì)象發(fā)生改變的時(shí)候被通知的對(duì)象 * @author zc * @version 1.0 2017-08-29 */ public interface Observer { /** * 更新的接口 * @param subject 傳入的目標(biāo)對(duì)象,方便獲取相應(yīng)的目標(biāo)對(duì)象的狀態(tài) */ void update(WeatherSubject subject); }
4.編寫(xiě)ConcreteObserver類
package com.myimooc.designpattern.c5observer.weather; /** * @describe 具體的觀察者對(duì)象,實(shí)現(xiàn)更新的方法,使自身的狀態(tài)和目標(biāo)的狀態(tài)保持一致 * @author zc * @version 1.0 2017-08-29 */ public class ConcreteObserver implements Observer { /** * 觀察者的名稱,是誰(shuí)收到了這個(gè)信息 */ private String observerName; /** * 天氣的內(nèi)容信息,這個(gè)消息從目標(biāo)處獲取 */ private String weatherContent; /** * 提醒的內(nèi)容,不同的觀察者提醒不同的內(nèi)容 */ private String remindThing; /** * 獲取目標(biāo)類的狀態(tài)同步到觀察者的狀態(tài)中 */ @Override public void update(WeatherSubject subject) { weatherContent = ((ConcreteWeatherSubject)subject).getWeatherContent(); System.out.println(observerName + " 收到了天氣信息 " + weatherContent + ",準(zhǔn)備去做 "+remindThing); } public String getObserverName() { return observerName; } public void setObserverName(String observerName) { this.observerName = observerName; } public String getWeatherContent() { return weatherContent; } public void setWeatherContent(String weatherContent) { this.weatherContent = weatherContent; } public String getRemindThing() { return remindThing; } public void setRemindThing(String remindThing) { this.remindThing = remindThing; } }
5.編寫(xiě)Client類
package com.myimooc.designpattern.c5observer.weather; /** * @describe 訂閱天氣-測(cè)試類 * @author zc * @version 1.0 2017-08-29 */ public class Client { public static void main(String[] args) { // 1.創(chuàng)建目標(biāo) ConcreteWeatherSubject weather = new ConcreteWeatherSubject(); // 2.創(chuàng)建觀察者 ConcreteObserver observerGiel = new ConcreteObserver(); observerGiel.setObserverName("黃明的女朋友"); observerGiel.setRemindThing("是我們的第一次約會(huì),地點(diǎn)街心公園,不見(jiàn)不散哦"); ConcreteObserver observerMum = new ConcreteObserver(); observerMum.setObserverName("老媽"); observerMum.setRemindThing("是一個(gè)購(gòu)物的好日子,明天去天虹掃貨"); // 3.注冊(cè)觀察者 weather.attach(observerGiel); weather.attach(observerMum); // 4.目標(biāo)發(fā)布天氣 weather.setWeatherContent("明天 天氣晴朗,藍(lán)天白云,氣溫28℃"); } }第三章:觀察者模式詳解 3-1 深入認(rèn)識(shí)
目標(biāo)與觀察者之間的關(guān)系
一對(duì)多的關(guān)系 一對(duì)一的關(guān)系(如果觀察者只有一個(gè))
單向依賴
在觀察者模式中,觀察者和目標(biāo)是單向依賴,只有觀察者依賴目標(biāo),而不是目標(biāo)依賴觀察者。主動(dòng)權(quán)掌握在目標(biāo)手中,只有目標(biāo)知道什么時(shí)候需要通知觀察者。
命名建議
觀察者模式又被稱為發(fā)布訂閱模式 目標(biāo)接口的定義,建議在名稱后面跟Subject 觀察者接口的定義,建議在名稱后面跟Observer 觀察者接口的更新方法,建議名稱為uodate
觸發(fā)通知的時(shí)機(jī)
一般情況下,是在完成了狀態(tài)維護(hù)后觸發(fā)。因?yàn)橥ㄖ獣?huì)傳遞數(shù)據(jù),不能先通知,后改數(shù)據(jù),這會(huì)導(dǎo)致觀察者和目標(biāo)對(duì)象狀態(tài)不一致。
觀察者模式的調(diào)用順序示意圖-準(zhǔn)備階段
運(yùn)行階段
通知的順序
從理論上來(lái)說(shuō),當(dāng)目標(biāo)對(duì)象的狀態(tài)發(fā)生改變時(shí),通知所有觀察者的時(shí)候,順序是不確定的。 因此,觀察者實(shí)現(xiàn)的功能,絕對(duì)不能依賴于通知的順序。 也就是說(shuō),多個(gè)觀察者之間的順序是平行的,相互不應(yīng)該有先后依賴的關(guān)系。3-2 推拉模型
推模型
目標(biāo)對(duì)象主動(dòng)向觀察者推送目標(biāo)的詳細(xì)信息 推送的信息通常是目標(biāo)對(duì)象的全部或部分?jǐn)?shù)據(jù) 相當(dāng)于是在廣播通訊
拉模型(第二章的實(shí)現(xiàn)屬于拉模型)
目標(biāo)對(duì)象在通知觀察者的時(shí)候,只傳遞少量信息 如果觀察者需要更具體的信息,由觀察者主動(dòng)到目標(biāo)對(duì)象中獲取 相當(dāng)于是觀察者從目標(biāo)對(duì)象中拉數(shù)據(jù) 一般這種模型的實(shí)現(xiàn)中,會(huì)把目標(biāo)對(duì)象自身通過(guò)update方法傳遞給觀察者
兩種模型的區(qū)別
推模型是假定目標(biāo)對(duì)象知道觀察者需要的數(shù)據(jù) 推模型會(huì)使觀察者對(duì)象難以復(fù)用 拉模型是目標(biāo)對(duì)象不知道觀察者具體需要什么數(shù)據(jù),因此把自身傳給觀察者,由觀察者來(lái)取值 拉模型下,update方法的參數(shù)是目標(biāo)對(duì)象本身,基本上可以適應(yīng)各種情況的需要3-3 Java實(shí)現(xiàn)
Java實(shí)現(xiàn)與自己實(shí)現(xiàn)的對(duì)比
不需要再定義觀察者和目標(biāo)的接口了,JDK定義好了 具體的目標(biāo)實(shí)現(xiàn)里面不需要再維護(hù)觀察者的注冊(cè)信息了,JDK在Observable類里面實(shí)現(xiàn)好了 觸發(fā)通知的方式有一點(diǎn)變化,要先調(diào)用setChanged方法,這是為了實(shí)現(xiàn)更精確的觸發(fā)控制 具體觀察者的實(shí)現(xiàn)里面,update方法能同時(shí)支持推模型和拉模型
代碼編寫(xiě)
1.編寫(xiě)ConcreteWeatherSubject類
package com.myimooc.designpattern.c5observer.weatherjdk; import java.util.Observable; /** * @describe 使用JDK實(shí)現(xiàn)觀察者模式,天氣目標(biāo)具體實(shí)現(xiàn)類 * @author zc * @version 1.0 2017-08-29 */ public class ConcreteWeatherSubject extends Observable { /** 天氣情況的內(nèi)容 */ private String content; public String getContent() { return content; } public void setContent(String content) { this.content = content; // 天氣情況有了,就要通知所有的觀察者 // 在用Java中的Observer模式時(shí),需要先調(diào)用setChanged方法 this.setChanged(); // 調(diào)用通知方法-推模型 this.notifyObservers(content); // 調(diào)用通知方法-拉模型 // this.notifyObservers(); } }
2.編寫(xiě)ConcreteObserver類
package com.myimooc.designpattern.c5observer.weatherjdk; import java.util.Observable; import java.util.Observer; /** * @describe 使用JDK實(shí)現(xiàn)觀察者模式,具體的觀察者對(duì)象 * @author zc * @version 1.0 2017-08-29 */ public class ConcreteObserver implements Observer { /** 觀察者的名稱,是誰(shuí)收到了這個(gè)信息 */ private String observerName; @Override public void update(Observable o, Object arg) { // 推模型 System.out.println(observerName + " 收到了消息,目標(biāo)推送過(guò)來(lái)的是 "+arg); // 拉模型 ConcreteWeatherSubject concreteWeatherSubject = (ConcreteWeatherSubject)o; System.out.println(observerName + " 收到了消息,主動(dòng)到目標(biāo)對(duì)象中去拉 "+concreteWeatherSubject.getContent()); } public String getObserverName() { return observerName; } public void setObserverName(String observerName) { this.observerName = observerName; } }
3.編寫(xiě)Client類
package com.myimooc.designpattern.c5observer.weatherjdk; /** * @describe 使用JDK實(shí)現(xiàn)觀察者模式,測(cè)試類 * @author zc * @version 1.0 2017-08-29 */ public class Client { public static void main(String[] args) { // 創(chuàng)建天氣作為一個(gè)目標(biāo),也可以說(shuō)是被觀察者 ConcreteWeatherSubject subject = new ConcreteWeatherSubject(); // 創(chuàng)建黃明的女朋友作為觀察者 ConcreteObserver observerGiel = new ConcreteObserver(); observerGiel.setObserverName("黃明的女朋友"); // 創(chuàng)建黃明的老媽作為觀察者 ConcreteObserver observerMum = new ConcreteObserver(); observerMum.setObserverName("老媽"); // 注冊(cè)觀察者 subject.addObserver(observerGiel); subject.addObserver(observerMum); // 目標(biāo)更新天氣情況 subject.setContent("明天 天氣晴朗,藍(lán)天白云,氣溫28℃"); } }3-4 優(yōu)點(diǎn)缺點(diǎn)
簡(jiǎn)述觀察者優(yōu)缺點(diǎn)
優(yōu)點(diǎn) 觀察者模式實(shí)現(xiàn)了觀察者和目標(biāo)之間的抽象耦合 觀察者模式實(shí)現(xiàn)了動(dòng)態(tài)聯(lián)動(dòng)(所謂聯(lián)動(dòng)是指做一個(gè)操作會(huì)引起其它相關(guān)的操作) 觀察者模式支持廣播通信 缺點(diǎn) 可能會(huì)引起無(wú)謂的操作3-5 何時(shí)使用
觀察者模式的本質(zhì)
觸發(fā)聯(lián)動(dòng)
建議在以下情況中選用觀察者模式
當(dāng)一個(gè)抽象模型有兩個(gè)方面,其中一個(gè)方面的操作依賴于另一個(gè)方面的狀態(tài)變化 如果在更改一個(gè)對(duì)象的時(shí)候,需要同時(shí)連帶改變其他的對(duì)象, 而且不知道究竟應(yīng)該有多少對(duì)象需要被連帶改變 當(dāng)一個(gè)對(duì)象必須通知其他的對(duì)象,但是又希望這個(gè)對(duì)象和被它通知的對(duì)象是松散耦合的第四章:觀察者模式衍生 4-1 特殊場(chǎng)景
需求總結(jié)
區(qū)別對(duì)待觀察者 需要根據(jù)不同的天氣情況來(lái)通知不同的觀察者 黃明的女朋友只想接收 下雨的天氣預(yù)報(bào) 黃明的老媽想接收 下雨或者下雪的天氣預(yù)報(bào)
解決思路
當(dāng)天氣更新時(shí),在目標(biāo)天氣中進(jìn)行判斷,如果不符合觀察者的條件,則不進(jìn)行通知4-2 代碼示例
實(shí)現(xiàn)步驟
1.定義目標(biāo)的抽象類和觀察者的接口 2.實(shí)現(xiàn)目標(biāo)的類和觀察者接口 3.編寫(xiě)測(cè)試類進(jìn)行測(cè)試
代碼編寫(xiě)
1.編寫(xiě)WeatherSubject類
package com.myimooc.designpattern.c5observer.weathercondition; import java.util.ArrayList; import java.util.List; /** * @describe 天氣目標(biāo)抽象類 * @author zc * @version 1.0 2017-08-29 */ public abstract class WeatherSubject { /** 用來(lái)保存注冊(cè)的觀察者對(duì)象 */ protected Listobservers = new ArrayList (); /** * 增加觀察者 */ public void attach(Observer observer){ observers.add(observer); } /** * 刪除觀察者 */ public void detach(Observer observer){ observers.remove(observer); } /** * 區(qū)別通知觀察者-由子類實(shí)現(xiàn) */ protected abstract void notifyObservers(); }
2.編寫(xiě)Observer類
package com.myimooc.designpattern.c5observer.weathercondition; /** * @describe 觀察者接口,定義一個(gè)更新的接口給那些在目標(biāo)對(duì)象發(fā)生改變的時(shí)候被通知的對(duì)象 * @author zc * @version 1.0 2017-08-29 */ public interface Observer { /** * 更新的接口 * @param subject 傳入的目標(biāo)對(duì)象,方便獲取相應(yīng)的目標(biāo)對(duì)象的狀態(tài) */ void update(WeatherSubject subject); /** 設(shè)置觀察者名稱 */ void setObserverName(String observerName); /** 獲取觀察者名稱 */ String getObserverName(); }
3.編寫(xiě)ConcreteWeatherSubject類
package com.myimooc.designpattern.c5observer.weathercondition; import java.util.Objects; /** * @describe 天氣目標(biāo)的實(shí)現(xiàn)類 * @author zc * @version 1.0 2017-08-29 */ public class ConcreteWeatherSubject extends WeatherSubject { // 天氣情況:晴天、下雨、下雪 // 目標(biāo)對(duì)象的狀態(tài) private String weatherContent; @Override protected void notifyObservers() { // 遍歷所有注冊(cè)的觀察者 this.observers.forEach(observer -> { // 規(guī)則是: // 黃明的女朋友 需要 下雨 的條件通知,其他條件不通知 // 黃明的老媽 需要 下雨 或者 下雪 的條件通知,其他條件不通知 // 如果天氣是晴天 // do nothing... // 如果天氣是下雨 if(Objects.equals("下雨", this.getWeatherContent())){ if(Objects.equals("黃明的女朋友", observer.getObserverName())){ observer.update(this); } if(Objects.equals("黃明的老媽", observer.getObserverName())){ observer.update(this); } } // 如果天氣是下雪 if(Objects.equals("下雪", this.getWeatherContent())){ if(Objects.equals("黃明的老媽", observer.getObserverName())){ observer.update(this); } } }); } public String getWeatherContent() { return weatherContent; } public void setWeatherContent(String weatherContent) { this.weatherContent = weatherContent; this.notifyObservers(); } }
4.編寫(xiě)ConcreteObserver類
package com.myimooc.designpattern.c5observer.weathercondition; /** * @describe 觀察者的實(shí)現(xiàn)類 * @author zc * @version 1.0 2017-08-29 */ public class ConcreteObserver implements Observer { /** * 觀察者的名稱,是誰(shuí)收到了這個(gè)信息 */ private String observerName; /** * 天氣的內(nèi)容信息,這個(gè)消息從目標(biāo)處獲取 */ private String weatherContent; /** * 提醒的內(nèi)容,不同的觀察者提醒不同的內(nèi)容 */ private String remindThing; /** * 獲取目標(biāo)類的狀態(tài)同步到觀察者的狀態(tài)中 */ @Override public void update(WeatherSubject subject) { weatherContent = ((ConcreteWeatherSubject)subject).getWeatherContent(); System.out.println(observerName + " 收到了天氣信息 " + weatherContent + ",準(zhǔn)備去做 "+remindThing); } @Override public String getObserverName() { return observerName; } @Override public void setObserverName(String observerName) { this.observerName = observerName; } public String getWeatherContent() { return weatherContent; } public void setWeatherContent(String weatherContent) { this.weatherContent = weatherContent; } public String getRemindThing() { return remindThing; } public void setRemindThing(String remindThing) { this.remindThing = remindThing; } }
5.編寫(xiě)Client類
package com.myimooc.designpattern.c5observer.weathercondition; /** * @describe 區(qū)別對(duì)待觀察者測(cè)試類 * @author zc * @version 1.0 2017-08-29 */ public class Client { public static void main(String[] args) { // 1.創(chuàng)建目標(biāo) ConcreteWeatherSubject weather = new ConcreteWeatherSubject(); // 2.創(chuàng)建觀察者 ConcreteObserver observerGiel = new ConcreteObserver(); observerGiel.setObserverName("黃明的女朋友"); observerGiel.setRemindThing("下雨了,安靜的呆在家里吧"); ConcreteObserver observerMum = new ConcreteObserver(); observerMum.setObserverName("黃明的老媽"); observerMum.setRemindThing("不管下雨還是下雪,我都不出門(mén)了"); // 3.注冊(cè)觀察者 weather.attach(observerGiel); weather.attach(observerMum); // 4.目標(biāo)發(fā)布天氣 weather.setWeatherContent("天氣"); weather.setWeatherContent("下雪"); weather.setWeatherContent("下雨"); } }第五章:觀察者模式總結(jié) 5-1 課程總結(jié)
總結(jié)
觀察者模式簡(jiǎn)介:場(chǎng)景描述 觀察者模式實(shí)戰(zhàn):模式原理 觀察者模式詳解:推拉模型、JDK實(shí)現(xiàn)、優(yōu)缺點(diǎn) 觀察者模式衍生:區(qū)別對(duì)待觀察者
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/70294.html
時(shí)間:2017年08月30日星期三說(shuō)明:本文部分內(nèi)容均來(lái)自慕課網(wǎng)。@慕課網(wǎng):http://www.imooc.com教學(xué)源碼:https://github.com/zccodere/s...學(xué)習(xí)源碼:https://github.com/zccodere/s... 第一章:責(zé)任鏈模式簡(jiǎn)介 1-1 課程簡(jiǎn)介 課程大綱 什么是責(zé)任鏈模式 如何實(shí)現(xiàn)責(zé)任鏈模式 責(zé)任鏈模式如何解耦 責(zé)任鏈模式的應(yīng)用 案例:...
時(shí)間:2017年08月27日星期日說(shuō)明:本文部分內(nèi)容均來(lái)自慕課網(wǎng)。@慕課網(wǎng):http://www.imooc.com教學(xué)源碼:https://github.com/zccodere/s...學(xué)習(xí)源碼:https://github.com/zccodere/s... 第一章:?jiǎn)卫J胶?jiǎn)介 1-1 簡(jiǎn)介 單例模式 概念及應(yīng)用場(chǎng)合 餓漢模式 懶漢模式 餓漢模式與懶漢模式的區(qū)別 什么是設(shè)計(jì)模式 是一套被反...
摘要:時(shí)間年月日星期二說(shuō)明本文部分內(nèi)容均來(lái)自慕課網(wǎng)。慕課網(wǎng)教學(xué)源碼學(xué)習(xí)源碼第一章適配器模式的簡(jiǎn)介簡(jiǎn)介生活中的適配器翻譯軟件插座適配器適配器模式定義適配器模式講將一個(gè)類的接口,轉(zhuǎn)換成客戶期望的另外一個(gè)接口。 時(shí)間:2017年08月29日星期二說(shuō)明:本文部分內(nèi)容均來(lái)自慕課網(wǎng)。@慕課網(wǎng):http://www.imooc.com教學(xué)源碼:https://github.com/zccodere/s.....
摘要:時(shí)間年月日星期六說(shuō)明本文部分內(nèi)容均來(lái)自慕課網(wǎng)。案例介紹飲料機(jī)配置模版把水煮沸泡飲料把飲料倒進(jìn)杯子加調(diào)味料第二章模版模式實(shí)現(xiàn)基本框架代碼編寫(xiě)編寫(xiě)類模版模式抽象基類,為所有子類提供一個(gè)算法框架。 時(shí)間:2017年09月02日星期六說(shuō)明:本文部分內(nèi)容均來(lái)自慕課網(wǎng)。@慕課網(wǎng):http://www.imooc.com教學(xué)源碼:https://github.com/zccodere/s...學(xué)習(xí)源...
時(shí)間:2017年08月31日星期四說(shuō)明:本文部分內(nèi)容均來(lái)自慕課網(wǎng)。@慕課網(wǎng):http://www.imooc.com教學(xué)源碼:https://github.com/zccodere/s...學(xué)習(xí)源碼:https://github.com/zccodere/s... 第一章:策略模式簡(jiǎn)介 1-1 簡(jiǎn)介 課程大綱 什么是策略模式 策略模式如何實(shí)現(xiàn) 策略模式總結(jié)篇 實(shí)例案例分享 日常生活中的策略 Wor...
閱讀 975·2023-04-26 02:49
閱讀 1187·2021-11-25 09:43
閱讀 2558·2021-11-18 10:02
閱讀 2933·2021-10-18 13:32
閱讀 1294·2019-08-30 13:54
閱讀 2092·2019-08-30 12:58
閱讀 3023·2019-08-29 14:06
閱讀 2166·2019-08-28 18:10