资源描述:
《web系统与技术实验6》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Web系统与技术实验报告(实验六)学号:姓名:实验项目名称:对象的创建教师评分:一、实验目的了解对象创建的几种方式二、预习内容及要求(要求写出预习内容)工厂模式创建对象的方法,存在的问题构造函数创建对象的方法,存在的问题原型模式创建对象的方法,存在的问题三、实验内容、操作过程及实验结果记录1.如果有一个java类Socket,其声明如下:classSocket{publicStringlocalAddress;//本地ip地址publicintlocalPort;//本地端口号publicintconnect(StringremoteAddress,intremotePort)//连接方法{r
2、eturnlocalPort;}}he"governingforthepeople","Nomattertheinterestsofthemasses"conceptunderstandingisnotinplace.Thespecificworktreatswiththedeployment,afewleadingcadrescomplainthatworkistoocomplicated,toomuchresponsibility,thepressureistoolarge,toomuchemphasisonthedifficultyofthework.Forexample,noncoal
3、mine请在javascript中分别使用工厂模式、构造函数模式和原型模式创建两个对象socket1和socket2,并为socket1和socket2初始化其成员变量。例如在java中,可以:Socketsocket1=newSocket();socket1.localAddress="192.168.1.20"socket1.localPort=9000Socketsocket2=newSocket();socket2.localAddress="202.116.1.30"socket2.localPort=100002.在三种模式创建的对象中,显示socket1和socket2的类型he
4、"governingforthepeople","Nomattertheinterestsofthemasses"conceptunderstandingisnotinplace.Thespecificworktreatswiththedeployment,afewleadingcadrescomplainthatworkistoocomplicated,toomuchresponsibility,thepressureistoolarge,toomuchemphasisonthedifficultyofthework.Forexample,noncoalmine3.编程证明:用三种模式创建出
5、的对象socket1和socket2,其中的connect方法,在socket1和socket2中是否是同一个方法he"governingforthepeople","Nomattertheinterestsofthemasses"conceptunderstandingisnotinplace.Thespecificworktreatswiththedeployment,afewleadingcadrescomplainthatworkistoocomplicated,toomuchresponsibility,thepressureistoolarge,toomuchemphasisont
6、hedifficultyofthework.Forexample,noncoalmine四、实验过程中所遇问题思考与讨论(可写个人体会,或相关理论知识,根据个人具体情况选做)he"governingforthepeople","Nomattertheinterestsofthemasses"conceptunderstandingisnotinplace.Thespecificworktreatswiththedeployment,afewleadingcadrescomplainthatworkistoocomplicated,toomuchresponsibility,thepressur
7、eistoolarge,toomuchemphasisonthedifficultyofthework.Forexample,noncoalmine