ImageVerifierCode 换一换
格式:DOCX , 页数:15 ,大小:16.45KB ,
资源ID:3554094      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3554094.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(设计模式作业三源代码江苏大学版本.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

设计模式作业三源代码江苏大学版本.docx

1、设计模式作业三源代码江苏大学版本(1) 贷款 :模板方法模式using System;using System.Collections.Generic;using System.Linq;using System.Text;public abstract class examine/抽象模板类 public void FillItem1() Console.WriteLine(近来收支情况:); Console.WriteLine(Item1() + RMB); public void FillItem2() Console.Write(信用情况:); Console.WriteLine(It

2、em2(); public void FillItem3() Console.WriteLine(未来收支情况:); Console.WriteLine(Item3()+RMB); protected virtual string Item1() return ; protected virtual string Item2() return ; protected virtual string Item3() return ; public class CommonCustomer : examine protected override string Item1() return 月收入3

3、000 RMB,支出2000 ; protected override string Item2() return 良好; protected override string Item3() return 月收入5000 RMB,支出2500 ; public class CompanyCustomer : examine protected override string Item1() return 年收入1000万; protected override string Item2() return 良好; protected override string Item3() return

4、年收入1500万; namespace loan class Program static void Main(string args) Console.WriteLine(普通客户:); CommonCustomer s1 = new CommonCustomer(); s1.FillItem1(); s1.FillItem2(); s1.FillItem3(); System.Console.WriteLine(n); Console.WriteLine(企业客户:); CommonCustomer s2 = new CommonCustomer(); s2.FillItem1(); s2

5、.FillItem2(); s2.FillItem3(); (2) 天气预报:观察着模式using System;using System.Collections.Generic;using System.Linq;using System.Text;public abstract class Subject private List observers = new List(); public void attach(Observer o)/注册一个观察者 observers.Add(o); public void detach(Observer o) observers.Remove(o)

6、; public void notice() foreach (Observer observer in observers) observer.Update(); public abstract class Observer public abstract void Update(); public abstract void ShowDate();public class system : Subject private string weather; public string Weather get return weather; set weather = value; public

7、 class computer : Observer private string weather; private system sys; public computer(system sys) this.sys = sys; public override void Update() weather = sys.Weather; public override void ShowDate() Console.WriteLine(电脑上最新天气预报是:+weather); public class mobilephone : Observer private string weather1;

8、 private system sys1; public mobilephone(system sys) this.sys1 = sys; public override void Update() weather1 = sys1.Weather; public override void ShowDate() Console.WriteLine(手机上最新天气预报是: + weather1); public class Ipad : Observer private string weather2; private system sys2; public Ipad(system sys) t

9、his.sys2 = sys; public override void Update() weather2 = sys2.Weather; public override void ShowDate() Console.WriteLine(Ipad最新天气预报是: + weather2); namespace weatherforecast class Program static void Main(string args) system s = new system(); computer c = new computer(s); mobilephone m = new mobileph

10、one(s); Ipad pad = new Ipad(s); s.attach(c); s.attach(m); s.attach(pad); s.Weather = 今天晴转多云,最高温度26度,最低温度20度; s.notice(); c.ShowDate(); m.ShowDate(); pad.ShowDate(); (3) 天气预报:事件委托改写观察着模式using System;using System.Collections.Generic;using System.Linq;using System.Text;public delegate void NotifyEventH

11、andler(object sender);public class Weather public NotifyEventHandler NotifyEvent; private String _symbol; public Weather(String symbol) this._symbol = symbol; public void Update() OnNotifyChange(); public void OnNotifyChange() if (NotifyEvent != null) NotifyEvent(this); public String Symbol get retu

12、rn _symbol; public class Computer string _name; public Computer(string name) this._name = name; public void SendData(object obj) if (obj is Weather ) Weather weather= (Weather)obj; Console.WriteLine(0显示的天气是: 1 ,_name , weather.Symbol); namespace weather_delegate_ class Program static void Main(strin

13、g args) Weather weather = new Weather(今天晴转多云,最高温度26度,最低温度20度); Computer investor = new Computer(电脑); Computer investor1 = new Computer(手机); Computer investor2 = new Computer(Ipad); weather.NotifyEvent += new NotifyEventHandler(investor.SendData); weather.NotifyEvent += new NotifyEventHandler(investo

14、r1.SendData); weather.NotifyEvent += new NotifyEventHandler(investor2.SendData); weather.Update(); Console.ReadLine(); (4) 玉皇大帝下旨传美猴王上天:命令模式 using System;using System.Collections.Generic;using System.Linq;using System.Text;public abstract class imperial/Command protected monkey mk; public imperial(m

15、onkey m) this.mk = m; public abstract void Execute();public class report : imperial/ConcreteCommand public report(monkey m) : base(m) public override void Execute() mk.Fly(); public class taibai/Invoker private imperial imp; public void SetCommand(imperial im) Console.WriteLine(玉皇大帝下旨:传美猴王觐见!); this

16、.imp = im; public void ExecuteCommand() Console.WriteLine(传旨进行中); imp.Execute(); public class monkey/Reciver public void Fly() Console.WriteLine(美猴王接旨上天!玉皇大帝); namespace Command class Program static void Main(string args) monkey m = new monkey(); imperial imp = new report(m); taibai tb = new taibai(

17、); tb.SetCommand(imp); tb.ExecuteCommand(); (5) TCP Connection:状态模式 using System;using System.Collections.Generic;using System.Linq;using System.Text;public class TcpConnecion private TcpState state; public TcpConnecion(TcpState State) state = State; public void ChangeM(string st) state.ChangeM (thi

18、s,st); public bool ChangeState(TcpState ts) state=ts; return true; public abstract class TcpState public abstract void ChangeM(TcpConnecion tc, string st); public bool ChangeState(TcpConnecion tc,TcpState ts) tc.ChangeState(ts); return true; public class TCPEstablished:TcpState public override void

19、ChangeM(TcpConnecion tc, string st) if (st = Listen) Console.WriteLine(由Established状态变为Listen状态); TcpState es = new TCPEstablished(); ChangeState(tc,es); else if (st = Close) Console.WriteLine(由Established状态变为Close状态); TcpState cs = new TCPEstablished(); ChangeState(tc, cs); public class TCPListen :

20、 TcpState public override void ChangeM(TcpConnecion tc, string st) if (st = Established) Console.WriteLine(由Listen状态变为Established状态); TcpState cs = new TCPListen(); ChangeState(tc, cs); else if (st = Close) Console.WriteLine(由Listen状态变为Close状态); TcpState cs = new TCPListen(); ChangeState(tc, cs); pu

21、blic class TCPClosed : TcpState public override void ChangeM(TcpConnecion tc, string st) if (st = Established) Console.WriteLine(由Close状态变为Established状态); TcpState cs = new TCPClosed(); ChangeState(tc, cs); else if (st = Listen) Console.WriteLine(由Close状态变为Listen状态); TcpState cs = new TCPClosed(); C

22、hangeState(tc, cs); namespace TCPconnection class Program static void Main(string args) string st = Established; TcpState tcs= new TCPEstablished(); TcpConnecion tcn = new TcpConnecion(tcs); st = Listen; tcn.ChangeM(st); st = Close; tcn.ChangeM(st); Console.WriteLine(n); TcpState t2 = new TCPClosed(); TcpConnecion tc2 = new TcpConnecion(t2); string s2 = Close; s2 = Established; tc2.ChangeM(s2);

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1