Possible duplicate:
What is the meaning of OOP?
What are the advantages of using object-oriented programming over functionally oriented ones.
As a trivial example, consider:
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;
return vec3;
}
Now I am not very familiar with object-oriented programming, but the above translates to OOP as:
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) { ... };
};
My question is this? What really makes the second code example preferable to the first in modern programming? What are the advantages and disadvantages?
source
share