什么是使用过的功能为导向的面向对象编程的优点。
作为一个简单的例子考虑:
struct vector_t {
int x, y, z;
}
void setVector(vector_t *vector, int _x, int _y, it _z) {
vector->x = _x;
vector->y = _y;
vector->z = _z;
}
vector_t addVector(vector_t* vec1, vector_t* vec2) {
vector_t vec3;
vec3.x = vec1->x + vec2->x;
// and so on...
return vec3;
}
现在,我并不令人难以置信的熟悉面向对象的编程,但上面会转化为OOP:
class vector_t {
private:
int x, y, z;
public:
void set(int _x, int _y, int _z) { ... };
int getX() { return x; }
// ...
void addVector(vector_t *vec) { ... };
// ...
};
我的问题是这样的?真正使第二个代码示例如此优先于现代编程的第一个代码示例?有什么优点和缺点?
重复http://stackoverflow.com/questions/1161930/is-oop-abused-in-universities – 2010-09-13 04:57:48
重复http://stackoverflow.com/questions/24270/whats-the-point-of-oop – Frank 2010-09-13 05:09:00
顺便说一下,它被称为面向对象编程。 – Frank 2010-09-13 05:09:35