06-觀察者模式實(shí)驗(yàn)_第1頁
06-觀察者模式實(shí)驗(yàn)_第2頁
06-觀察者模式實(shí)驗(yàn)_第3頁
06-觀察者模式實(shí)驗(yàn)_第4頁
06-觀察者模式實(shí)驗(yàn)_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、課程實(shí)驗(yàn)報(bào)告課程名稱軟件設(shè)計(jì)與體系結(jié)構(gòu)班級(jí)軟件132實(shí)驗(yàn)日期20 1 5、06、02姓名m清華學(xué)號(hào)2 0 1 3 072 0 8實(shí)驗(yàn)成績實(shí)驗(yàn)名稱觀察者欖式實(shí)驗(yàn)實(shí)驗(yàn)?zāi)坑?及婆求實(shí)驗(yàn)環(huán)境 實(shí)驗(yàn)內(nèi)容(1)熟悉觀察者模式得核心思想:(2)掌握觀察者模式解決問題得方法。Win?, VS2O101、定義內(nèi)部數(shù)據(jù)列表U)內(nèi)部數(shù)據(jù)列表提供數(shù)據(jù):(2)每個(gè)數(shù)據(jù)列表項(xiàng)對(duì)應(yīng)界面表格中得一行.2、定義界面控件Da t aGridview3、利用觀察者欖式實(shí)現(xiàn)內(nèi)部1儲(chǔ)得數(shù)據(jù)列表數(shù)據(jù)發(fā)生變化時(shí)自動(dòng)更新DataGr i d v iew 中得內(nèi)容。算法描述及 實(shí)驗(yàn)步驟1 創(chuàng)建 mod e 1 類 Stu d e nt2. 創(chuàng)

2、建抽象U標(biāo)類da la3. 創(chuàng)建具體U標(biāo)類concrete dat a 4創(chuàng)建觀察者類Da t aGr i dview5類圖:StBllcBCKmme : sbincarc ; iBt ca : striiLrFstQdfBtlist nrdvieid.ictlttac2i (DalaCffiivicn() f-Ufltacli)()i甜Stvlat(B nuknt0 Melet百 todat (int)O Hiotifr 0 0 ();c la s s stude n tprivate st r in g name; privat e str i ng sex;private i n t a

3、 ge:pu blicstudent ($ tring nam e , $ t ri n g sesi i ntthis、name = n am e ;this、 sex = se X ;thi s、age = ag e:pub I i c s tring Nameget retu r n se t namep ubl i c s t rin gname;=value:Sexget (re turn sex: set sexvalue: public i nt Ageg et r e tu r n a ge; se I a ge = v a lue; Da、 cs:using Sys t em

4、:Sy S t e m、C o llec I ions:S y stem、C ollection s . G eneric;Sys tem、Linq; Sy s t em、T ex t :using Sy Stem、Threading、Tasks;nam e space $ hiya n _6a bstract classp r otecte dpro t ect e dd ataListst u dent) Stu dent List = newListA r ray List grid v i e wLi s t = new A r r/添加觀察者p ublic a bstract v o

5、id Att a c h (DataGridviev dataG r i dview):a yListO ;usingusingusingusingw)/ /刪除觀察者public abs tra c t vo i d Dat a ch (D a t aGridv i ev d a t a G r i d V iew):pub 1 icpubl i cp ublic/通知方法pub lie a bstabs t rac t void A ddStudent (st uD elet e Student (abstractabstractconcr e teDatSs c s :voidvoi d

6、r actD i s p la y ();VO id No I if y ():u $ i ng Sys t em;Sys t e m、Coll e c t ions. Ge ner i c ;S ystenix Lin q ;namesSystem、Text:System、Thread i ng、Tasks; p ace sh i ya n _6ass concret e Data: d a tapublic o V e r r id e void Atta c h (D a Igrpubl i cgri dv i e wList. Add (da to V err ide vo i d D

7、atai d vi e wLi $ t、Rem 0 vd e nt Stu);i nt loc):a Gridv i ew dataGridvi e w)a G r i dview);c h (Da taGri dview dataGridvie(d a t a Gr i dview);/實(shí)現(xiàn)通知方法pub I i c o V er r ide void Notin I i = 0;f orea ch (object o b ji fy 0i n gr i dviewList)Consol e、Wri t e (” 通知第(0)個(gè)觀察者:+十i ): (Da taGri d view) ob

8、j )、Up Date (this);/修改數(shù)pu b 1 i c ov e r r i de void AddS t u dent (st u d e nt s I u)stud e ntLis t % Add (stu);Notify 0:+s I u、Sex):us 1 ngu s 1 nusi n gProgr a OK c S :usin gpub i ic ove r r i de void Del e teStu d e nt (in t 1 o c )stud ent L ist. Remo veAt loc);N 0 ti f y ();pub I ic o V e r r

9、i de voi d D is play()for each (student s t u i n s t u d en t L ist)da t aGr i dview、c sCon s ole% W r iteLin e ( s t u、Xame+ * * + stu、Age+” u $ i n g S y st e m:using S ys t em、C ollect i ons、Ge n e ric: usin g System L inq:u $ i ng System、Text;using Syst e m. Thread i ng:、Task s ;n ame $ pa c e

10、s hi y a n _6class Da t aGridv i ewpri V at e data data = new concreteData ():p u b 1 i c Da t aGri d view (da t a data) t h is、dat a = d ata:Consol e、WriteLi n e (” 創(chuàng)建個(gè) DataGr i dview );p ublic voi d Up Da t e (data data)t h is、da ta = da t a ;Console. WriteLine (” 數(shù)據(jù)改變!”):I his、data、Di s play C);S

11、ys I em;Sys tem、Co 1 lec I ions、G e n e ri c ; g System、Linq:System、Text;usin g System、T h read i ng% Tasks: nam e space sh i yan_6cla s S Program1):S tudent Stu:al);1 8):Console、 ReadLine ():stati c V o id Ma i n ( stri n g arg s ) da t a d a ta L = new con ere t e D a ta():DataGridview dataG r idv i ew 1 = new Da t aGridvi e w (da tdata 1 Atta ch ;/ /D ataGr i dvi ew dataGr idvi e w3 = ne w D ataG rid view(datal): / / datal. Attach( d ataGridview 3 );Cons o 1 e s Wri t eLine (*給 d a ta 添加數(shù)據(jù));for (i n t

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論