I think the interviewer was trying to investigate this knowledge of “abstraction” and “data hiding”.
As the interviewer said, “some people begin to close,” “some people press more than necessary,” etc., what he was looking for is an abstraction of one function called “close.”
Fridge fridge = new Fridge(); fridge.close();
The answer will be: I would single out a function called close (), which will calculate how much force you need to close the refrigerator door and close. When we do this, even if you press or press more, the close method will calculate what force needs to be closed and closed.
The implementation is hidden. He can implement a simple close button on the refrigerator, which will use the power from the engine and close it. OR no matter what the user applies, he will simply take the force necessary to close and close the refrigerator beautifully, without sounds :)
Encapsulation:. I'm not sure if this is technically considered a template (I haven't clicked on them for a while), but this is a good rule for life. Basically, encapsulation means that you should only expose what is needed to use an object or control, and not expose things that can lead to the creation of unnecessary dependencies. Generally, the less dependencies you have, the better.
source share