H
H
heartdevil2017-08-02 11:43:29
OOP
heartdevil, 2017-08-02 11:43:29

Do pointers and denaming in c++ violate OOP principles?

Please explain, is it true that pointers and denaming in c++ violate OOP principles (encapsulation, inheritance, polymorphism)?
In my opinion, one does not apply to the other. Well, or applicable, but in "isolated places".
I'm not special in either this or that :), I just had a question.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2017-08-02
@heartdevil

Let's not get stuck in the holivar "should the pointer be an object." Let's assume that the pointer is the simplest type, for the sake of compatibility and efficiency.
Encapsulation and inheritance are not applicable to the simplest type.
And here for polymorphism pointers are very necessary. Dynamic polymorphism is when different objects can appear under the same facade.
1. It is impossible to transfer them by copy, only by pointer / link.
2. They cannot be destroyed one size fits all. So, if we transfer them to someone else's possession, we need to make sure that they are created on the "heap" and that the "facade" has a virtual destructor.
There are two more principles of OOP - abstraction and the Liskov principle. The first has to do with pointers insofar as there is polymorphism. The second is Google "covariant/contravariant pointers".

S
Stanislav B, 2017-08-02
@S_Borchev

Not

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question