您的位置:首页 > 其它

经典软件体系结构风格(一)

2017-03-13 18:23 176 查看
1.主程序-子程序软件体系结构   

组件–主程序、子程序

连接件–调用-返回机制

拓扑结构–层次化结构

主程序-子过程风格的优点与缺点

§优点:

–有效地将一个较复杂的程序系统设计任务分解成许多易于控制和处理的子任务,便于开发和维护–已被证明是成功的设计方法,可以被用于较大程序

缺点:

–规模:程序超过10万行,表现不好;程序太大,开发太慢,测试越来越困难

–可重用性差、数据安全性差,难以开发大型软件和图形界面的应用软件

–把数据和处理数据的过程分离为相互独立的实体,当数据结构改变时,所有相关的处理过程都要进行相应的修改

–图形用户界面的应用程序,很难用过程来描述和实现,开发和维护也都很困难。

*代码段一

#include <iostream>
using namespace std;
int max(int x,int y)
{
int z;
z=x>y?x:y;
return (z);
}
int main()
{
int a,b,c;
cin>>a>>b;
c=max(a,b);
cout<<"最大的数是:"<<c<<endl;
return 0;
}


*代码段二

#include <iostream>
using namespace std;
int jie(int num)
{
int sum=1;
for(int i=1; i<=num; i++)
{
sum*=i;
}
return sum;
}
int main()
{
int num;
cin>>num;
cout<<"num的阶乘是:"<<jie(num)<<endl;
return 0;
}

2.数据抽象和面向对象体系结构

组件是:类和对象

连接件:对象之间通过功能与函数调用实现交互。

OO风格优点

§复用和维护:利用封装和聚合提高生产力

–因为对象对其它对象隐藏它的表示,所以可以改变一个对象的表示,而不影响其它的对象。

–某一组件的算法与数据结构的修改不会影响其他组件

–组件之间依赖性降低,提高了复用度

§反映现实世界

§容易分解一个系统

–设计者可将一些数据存取操作的问题分解成一些交互的代理程序的集合

OO风格缺点

§管理大量的对象:怎样确立大量对象的结构

§继承引起复杂度,关键系统中慎用

§必须知道对象的身份

–为了使一个对象和另一个对象通过过程调用等进行交互,必须知道对象的标识。只要一个对象的标识改变了,就必须修改所有其他明确显式调用它的对象,并消除由此带来的一些副作用(例如,如果A使用了对象B,C也使用了对象B,那么,C对B的使用所造成的对A的影响可能是料想不到的)

*代码段一

class Spot{
private int x,y;
Spot(int u,int v){
setX(u);
setY(v);
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
class Trans{
void move(Spot p,int h, int k){
p.setX(p.getX()+h);
p.setY(p.getY()+k);
}
}
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Spot s=new Spot(2, 3);
System.out.println("s的坐标为:"+s.getX()+","+s.getY());
Trans ts=new Trans();
ts.move(s, 4, 5);
System.out.println("移动后s的坐标为:"+s.getX()+","+s.getY());
}

}


*代码段二

class reg{
private int length;
private int width;
public reg() {
super();
// TODO Auto-generated constructor stub
}
reg(int l,int w){
setLength(l);
setWidth(w);
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
int area(int l,int w){
int area;
area=l*w;
return area;
}
}
class regZhu{
int Vol(reg R,int h){
int Vol;
Vol=R.getLength()*R.getWidth()*h;
return Vol;
}
}
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
reg R=new reg(5,6);
int S=R.area(5, 6);
System.out.println("长方形的面积为:"+S);
regZhu RZ=new regZhu();
int vol=RZ.Vol(R, 5);
System.out.println("长方柱的体积为:"+vol);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: