D
D
Dom Alfro2019-02-25 13:06:23
OOP
Dom Alfro, 2019-02-25 13:06:23

What does hiding mean?

Good day! I'm not very sick and I can't concentrate on such an interesting term - like hiding - although I didn't understand much or maybe not - but I would like to understand - what it is and how to implement it - I searched but did not find a satisfactory answer - I will very grateful for the help!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Northern Lights, 2019-02-25
@mustang_shelby

Encapsulation

M
Mercury13, 2019-02-25
@Mercury13

This means: it must be difficult or impossible to bring an object out of its "adequate" state (which is called a class invariant ). All sensitive fields are hidden from prying eyes. (Of course, there may be “unsafe” methods, but then the user is an evil pinocchio to himself).
PHP manages memory itself (something seems to me that the memory management method there is “throw an object and fool with it”). But let's imagine that we need to call the "destroy object" command, and further access to the freed pointer is incorrect. Let's try to make an object "multiple ownership pointer".
In each of the managed objects, we set up a counter; when reassigning, the counter will have such a figure as how many pointers “look” at the object. The counter drops to zero - the object is destroyed. Accordingly, the "counter" managed object field and the "pointer to object" pointer field are hidden. I have already described the “adequate state”: “the counter will have such a figure as how many pointers “look” at the object. The counter drops to zero - the object is destroyed.

E
Evgeny, 2019-02-25
Maltsev @maltsever

Information hiding is often called encapsulation, but this is not entirely correct. Information hiding is a kind of restriction of access to such fields / methods / etc., which can only be changed inside the module. A typical example: declaring private variables.
Encapsulation is the hiding of implementation details . I like the following real life encapsulation example. We have an object - a watch, this object implements the IGetTime interface. We just look at the clock and get the time. At the same time, we are not at all interested in how this time was calculated inside the watch, what tools were used, mechanical watches or digital ones - it doesn’t matter. It is important that we know the time, and everything else is implementation details that are hidden from us. Likewise in OOP.
Thus, information hiding is only part of encapsulation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question