预览加载中,请您耐心等待几秒...
1/8
2/8
3/8
4/8
5/8
6/8
7/8
8/8

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

实验报告 课程:设计模式实验学期:2010-2011学年第一学期任课教师: 专业:学号:姓名:成绩: 实验4抽象工厂模式 1.题目: 使用抽象工厂模式实现一个DIY电脑店,其中的电脑配置有三个种类:学生版、家庭装、豪华版。 2.模式设计的UML类图: 3.程序源代码: (1)计算机配置工厂接口ComputerConfigurationFactory.java: publicinterfaceComputerConfigurationFactory { publicCpucreateCpu(); publicRamcreateRam(); publicMainboardcreateMainboard(); publicHarddiskcreateHarddisk(); publicDisplaycreateDisplay(); } (2)计算机配置工厂接口的各个子类: publicclassStudentComputerConfigurationFactoryimplementsComputerConfigurationFactory { publicCpucreateCpu() {returnnewStudentCpu();} publicRamcreateRam() {returnnewStudentRam();} publicMainboardcreateMainboard() {returnnewStudentMainboard();} publicHarddiskcreateHarddisk() {returnnewStudentHarddisk();} publicDisplaycreateDisplay() {returnnewStudentDisplay();} } publicclassHomeComputerConfigurationFactoryimplementsComputerConfigurationFactory { publicCpucreateCpu() {returnnewHomeCpu();} publicRamcreateRam() {returnnewHomeRam();} publicMainboardcreateMainboard() {returnnewHomeMainboard();} publicHarddiskcreateHarddisk() {returnnewHomeHarddisk();} publicDisplaycreateDisplay() {returnnewHomeDisplay();} } publicclassDeluxeComputerConfigurationFactoryimplementsComputerConfigurationFactory { publicCpucreateCpu() {returnnewDeluxeCpu();} publicRamcreateRam() {returnnewDeluxeRam();} publicMainboardcreateMainboard() {returnnewDeluxeMainboard();} publicHarddiskcreateHarddisk() {returnnewDeluxeHarddisk();} publicDisplaycreateDisplay() {returnnewDeluxeDisplay();} } (3)电脑各种配置的接口: publicinterfaceCpu { publicStringtoString(); } publicinterfaceRam { publicStringtoString(); } publicinterfaceMainboard { publicStringtoString(); } publicinterfaceHarddisk { publicStringtoString(); } publicinterfaceDisplay { publicStringtoString(); } (4)电脑配置Cpu接口的各个子类: publicclassStudentCpuimplementsCpu { publicStringtoString() {return"Intel奔腾双核E5400(盒)";} } publicclassHomeCpuimplementsCpu { publicStringtoString() {return"Intel酷睿i5650(盒)";} } publiccl