什麼是使用過的功能爲導向的面向對象編程的優點。
作爲一個簡單的例子考慮:
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