第五章 接口與抽象類的應用-v1.ppt_第1頁
第五章 接口與抽象類的應用-v1.ppt_第2頁
第五章 接口與抽象類的應用-v1.ppt_第3頁
第五章 接口與抽象類的應用-v1.ppt_第4頁
第五章 接口與抽象類的應用-v1.ppt_第5頁
已閱讀5頁,還剩38頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、第5章抽象類和接口應用程序、抽象類應用程序、abstract class person private string name;專用int agePublic person (string name,intage)this . name=name;This.age=agepublic string get name()return this . name;public intge tage()returnthis . age;public abstract String get content();public void say()system . out . print ln(this .

2、get content();class student extends person private float score;Public student (string name,intage,float score) super (name,age);This.score=scorePublic String getContent() return學生說:名字:super.getName()年齡: super.getAge()成績3360 this.score,classPublic worker (string name,intage,float salary) super (name,

3、age);This.salary=salaryPublic String getContent() return工人表示,姓名:super.getName()年齡: super.getAge()薪金3360 this.salary,public clar aryper 1 . say();per 2 . say();接口應用程序,界面Usb public void start();界面Usb public void start();public void stop();class computer public static void plugin(USB USB)USB . start();

4、USB . stop();public void stop();class computer public static void plugin(USB USB)USB . start();USB . stop();class flash implements USB public voidstart()system . out . print ln(USB驅(qū)動器開始工作)。);public void stop()system . out . print ln(USB閃存盤鎖定)。);class print implements USB public void start()system .

5、out . print ln(啟動打印機);public void stop()system . out . print ln(USB閃存盤鎖定)。);public class abstract _ 1 public static void main(string args)computer . plugin(new flash();computer . plugin(new print();適配器模式,interface Windows public void open();public void close();public void icon();public void uni con(

6、);abstract class windows adpater impe ments windows public void open();public void close();public void icon();public void uni con();class my windows extends windows adpater public void open()system . out . print ln(打開窗口!);public class testjiekou public static void main(string args)windows win=new my

7、 windows();win . open();factory模式,interface Fruit public void eat();classappleimplementsfruit public voideat()system . out . print ln(吃蘋果!);class orange implements fruit public void eat()system . out . print ln(吃橘子!);public class testjiekou 2 public static void main(string args)fruit f=new apple();f

8、 . eat();添加工廠類,類工廠/工廠類public static fruit getfruit(string class name)fruit f=null;if(apple . equals(class name)f=new apple();if(orange . equals(class name)f=new orange();return f;public class test jiekou 22 public static void main(string args)fruit f=factory . get fruit(args 0);If (f)!=null)f . eat(

9、);代理模式,interface give public void give money();class real give implements give public void give money()system . out . print ln(把錢還給我!);代理部分,class ProxyGive implements Give/代理private Give give=nullpublic proxy give(givegive)this . give=give;public void before()system . out . print ln(準備強制工具);public v

10、oid give money()this . before();this . give . give money();this . after();public void after()system . out . print(清除證據(jù));public class testjiekou 3 public static void main(string args)givegive=new proxy give(new real give();give . give money();提供用于控制、代理模式、代理模式和對其他對象的訪問的代理。provide a surrogate or placeh

11、older for another object to control access to it,類型界面,package com . CBF . proxy;public interface kind women public void makeeyeswithman();public void happy with man();潘金蓮,package com . CBF . proxy;public class panjinlian implements kind women public void happy withman()system . out . print ln(“潘金蓮在和

12、男人說話”);public void makeeyeswithman()system . out . print ln(潘金蓮眨眼的眼睛);package com . CB . proxy;public class Wang po implements kind women private kind women kind women kind women;Public WangPo() /默認情況下,PanJinLian的代理this . kind women=new PanJinLian();public Wang po(kind women kind women)this . kind w

13、omen=kind women;public void happy withman()this . kind women . happy withman();public void makeeyeswithman()this . kind women . makeeyeswithman();王夫人,西門慶,package com . CBE . proxy;public class ximen Qing public static void main(string args)/王波Wang po Wang po=new Wang po();/和西門慶要和潘金蓮見面,王奶奶在西門慶失去筷子的話劇

14、: wangpo . makeeyeswithman();/表面上是王奶奶在做,其實老板是潘金蓮王波. happywithman();Jia,public class jashi implements kind women public void happy withman()system . out . print ln(“愛的故事”);public void makeeyeswithman()system . out . print ln(Jia wink);西文經(jīng)和宰氏:package com . CBF . proxy;public class ximen Qing public st

15、atic void main(string args)/歷史改編,財和序言經(jīng):jashi jashi=new jashi();WangPo WangPo=new WangPo(jiaShi);/王太太是達西先生的代理人,王波. makeeyeswithman();wangpo . happywithman();實驗要求,使用大學卡片管理系統(tǒng)構建策略模型構建學生管理模塊,學生管理學生管理學生狀態(tài)管理,考勤管理,成績管理三部分構建E-R圖表,代理模型實驗,系統(tǒng)游戲利用代理模式構建世代游戲模塊構建游戲基本游戲,代理游戲,通關三部分構建模式代碼,策略模型,策略模型*首先確定策略界面諸葛亮老先生對趙云說

16、,周迅是三個妙計的界面。* */public interface IStrategy /每個錦囊妙計都是可行的算法。您的設計模式public void operate();界面,package com . CBF 4 life . strategy;/* * * *向祖國求助,使孫權無法殺死劉備*/public class back door implements istrategy public void operate()system . out . print ln,一個妙計,一個/* * * *請吳國泰打開綠燈*/public class given green light imple

17、ments istrategy public void operate()system . out . print ln(),妙計2,package com . CBF 4 life . strategy;/* * * *孫夫人斷絕后切斷追擊兵*/你的設計模式第6頁public class block enemy implements istrategy public void operate()system . out . prit,妙計3,妙計3/* * * * author CBF 4 life * im glad to share my knowledge with you all。*有了計謀*/public class Context /構造函數(shù),Public Context(istrategy s

溫馨提示

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

評論

0/150

提交評論