1 / 90
文档名称:

C++程序设计(part2).ppt

格式:ppt   页数:90页
下载后只包含 1 个 PPT 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

C++程序设计(part2).ppt

上传人:追风少年 2011/7/12 文件大小:0 KB

下载得到文件列表

C++程序设计(part2).ppt

文档介绍

文档介绍:C++程序设计(part 2)
Object-Oriented Programming
What?
Why?
How?
OOP
What
non-OO Solution
#include <>
#define STACK_SIZE 100
struct Stack
{ int top;
int buffer[STACK_SIZE];
};
void main()
{ Stack st1,st2;
= -1;
= -1;
int x;
push(st1,12);
pop(st1,x);
}
bool push(Stack &s, int i);
{ if ( == STACK_SIZE-1)
{ printf(“Stack is overflow.\n”);
return false; }
else
{ ++; [] = i;
return true; }
}
bool pop(Stack &s, int &i)
{ if ( == -1)
{ printf(“Stack is empty.\n”);
return false; }
else
{ i = []; --;
return true; }
}
OOP
OO Solution
#include <>
#define STACK_SIZE 100
class Stack
{ int top;
int buffer[STACK_SIZE];
public:
Stack() { top = -1; }
bool push(int i);
bool pop(int& i);
};
void main()
{ Stack st1,st2;
int x;
(12); (x);
(20); (x);
}
bool Stack::push(int i);
{ if (top == STACK_SIZE-1)
{ cout << “Stack is overflow.\n”;
return false; }
else
{ top++; buffer[top] = i;
return true; }
}
bool Stack::pop(int& i)
{ if (top == -1)
{ cout << “Stack is empty.\n”;
return false; }
else
{ i = buffer[top]; top--;
return true; }
}
OOP
Concepts
Program=Object1 + Object2 +……+ Objectn
Object: Data + Operation
Message: function call
Class
Object-Oriented
Object-Based
Only Provide Encapsulation
Without Inheritance
Ada, etc
OOP
Why
评价标准
Efficency of Development
Quality
External
Correctness、Efficiency、Robustness、Reliability
Usability、Reusability
Internal
Readability、Maintainability、Portability
HUI
UX
产品在规定的条件下和规定的时间内完成规定功能的能力
( 概率度量:可靠度)
需求
架构设计
构建模式
代码
测试用例
项目组织结构
OOP
Advantages
提高开发效率和软件质量
更高层次的抽象-数据抽象
数据封装
更好的模块化支持(高内聚、低耦合)
软件复用(部分重用)
对需求变更具有更好的适应性
OOP
How
Encapsulation
Object & Class
Object
数据:数据成员、成员变量、实例变量、对象的局部变量
操作:操作、方法、成员函数、消息处理过程
Class
对象属性的描述,是创建对象的模板
对象是类的实例
对象属于值的范畴,而类属于类型的范畴
OOP
Inheritance
is-a
软件重用(部分重用)
父类(Base class)、子类(Derived Class)
Single Inheritance
Multiple Inheritance
OOP
Polymorph