软件体系结构实验一

软件体系结构实验一

ID:10022561

大小:55.50 KB

页数:5页

时间:2018-05-21

软件体系结构实验一_第1页
软件体系结构实验一_第2页
软件体系结构实验一_第3页
软件体系结构实验一_第4页
软件体系结构实验一_第5页
资源描述:

《软件体系结构实验一》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、实验一经典软件体系结构风格实验课程名:软件体系结构理论及应用专业班级:软件工程学号:姓名:实验地点:k4-307指导教师:倪波一、实验目的(1)理解管道-过滤器软件体系结构、面向对象软件体系结构的原理(2)掌握管道-过滤器软件体系结构、面向对象软件体系结构的实例(3)管道-过滤器软件体系结构、面向对象软件体系结构的编程实现二、实验的内容和步骤1.管道-过滤器软件体系结构JavaI/O流中的管道流类PipedInputStream和PipedOutputStream可以方便地实现管道-过滤器体系结构,这两个类的实例对象要通过conne

2、ct方法连接。下面程序的功能是sender发送“Hello,receiver!I`msender”给receiver,然后receiver接受后显示出来并且在前面加上“thefollowingisfromsender”的信息。管道流内部在实现时还有大量的对同步数据的处理,管道输出流和管道输入流执行时不能互相阻塞,所以一般要开启独立线程分别执行,顺便复习了多线程操作。importjava.io.;importjava.util.;publicclassTestPiped{publicstaticvoidmain(String[]arg

3、s){senders=newsender();receiverr=newreceiver();PipedOutputStreamout=s.getOut();PipedInputStreamin=r.getIn();try{in.connect(out);s.start();r.start();}catch(Exceptione){e.printStackTrace();}}}classsenderextendsThread{PipedOutputStreamout=newPipedOutputStream();publicPipe

4、dOutputStreamgetOut(){returnout;}publicvoidrun(){Stringstr="Hello,receiver!I`msender";try{out.write(str.getBytes());out.close();}catch(Exceptione){e.printStackTrace();}}}classreceiverextendsThread{PipedInputStreamin=newPipedInputStream();publicPipedInputStreamgetIn()

5、{returnin;}publicvoidrun(){byte[]buf=newbyte[1024];try{intlen=in.read(buf);System.out.println("thefollowingisfromsender:"+newString(buf,0,len));in.close();}catch(Exceptione){e.printStackTrace();}}}程序的执行结果:2.数据抽象和面向对象软件体系结构有一个已知的二维坐标系,在坐标系中定义了若干种规则的图形:圆、正方形、矩形和椭圆。使用Ja

6、va语言进行面向对象的程序设计:(1)首先考虑数据封装性,(2)考虑继承性,(3)考虑抽象类。abstractclassGraph{protecteddoublex,y;//x,y是规则图形的中心点坐标publicGraph(doublex,doubley){//构造函数初始化中心点坐标this.x=x;this.y=y;}protectedvoidchangeX(doublex){//修改横坐标this.x=x;}protectedvoidchangeY(doubley){//修改纵坐标this.y=y;}publicabstra

7、ctdoublearea();//计算面积的抽象方法}classMySquareextendsGraph{privatedoublelength;publicMySquare(doublex,doubley,doublelength){super(x,y);this.length=length;}protectedvoidchangLength(doublelength){//修改边长lengththis.length=length;}publicdoublearea(){returnlengthlength;}}classMyCi

8、rcleextendsGraph{privatedoubleradius;publicMyCircle(doublex,doubley,doubleradius){super(x,y);this.radius=radius;}prot

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。