软件设计模式————(单例模式)
1.软件设计模式————(简单工厂模式)2.软件设计模式————(工厂方法模式)3.软件设计模式————(抽象工厂模式)4.软件设计模式————(建造者模式)5.软件设计模式————(原型模式)
6.软件设计模式————(单例模式)
7.软件设计模式————(适配器模式)8.软件设计模式————(桥接模式)9.软件设计模式————(组合模式)10.软件设计模式————(装饰模式)11.软件设计模式————(外观模式)12.软件设计模式————(享元模式)13.软件设计模式————(代理模式)14.软件设计模式————(命令模式)15.软件设计模式————(解释器模式)16.软件设计模式————(迭代器模式)17.软件设计模式————(中介者模式)18.软件设计模式————(备忘录模式)19.软件设计模式————(观察者模式)20.软件设计模式————(职责链模式)[实验任务一]:学号的单一
仿照课堂的身份证的例子,实现每个同学仅有一个学号这一问题。
实验要求:
1.画出对应的类图;
2.提交源代码;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | package test7; public class Client { public static void main(String[] args) { StudentID stu1,stu2; stu1=StudentID.getStudentID(); stu2=StudentID.getStudentID(); String str1,str2; str1=stu1.getID(); str2=stu2.getID(); System.out.println( "第一次学号:" +str1); System.out.println( "第二次学号:" +str2); } } 2 . package test7; public class StudentID { private static StudentID instance= null ; private String ID; public String getID() { return ID; } public void setID(String iD) { ID = iD; } private StudentID() { } public static StudentID getStudentID() { if (instance== null ) { instance= new StudentID(); instance.setID( "20194080" ); } else { System.out.println( "一个学生只能有一个学号" ); } return instance; } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix