Benefits of OOP

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;
  // and so on...
  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?

+3
source share
1 answer

OO , OO. (vector_t) (setVector, addVector ..), (.. ). , C ++, .

, , , .

+3

Source: https://habr.com/ru/post/1764431/


All Articles