📜 ⬆️ ⬇️

Encapsulation - black box?

Day after day, I’m worried about the problem of using someone else’s and my classes and libraries. When after some time you see that your code lacks the ability to redefine the behavior of a class and this interferes, and even worse, when a foreign library does not perform the tasks stated to it, even knowing where to fix and how you are limited by the code that was written in this library without the possibility of overriding. This article structures the encapsulation approach, which will make it possible not to waste time creating bicycles and save the efforts of programmers who use black boxes and create new ones.

Encapsulation is an art, not just a black box. The problem is - code that cannot be fixed, redefined, modified, etc. in the same project where it is used. Everything must be configured, redefined and changed. Universal soldier, who is called in the right situation and he saves the world, not waiting for the birth of a new soldier. And the solution is not to fix the source of libraries, because This is a time consuming process due to the simple lack of source code. It is easy to say these words, but it is more difficult to understand what they mean in programming languages ​​and how to correspond to them.

I want to say that encapsulation problems exist , but they are solved. You can look at the black box as an already finished product that is used to achieve the goal, as well as the material from which the form will be created to achieve the goal. We can give an example of an artist who uses paint for drawing and creates new paints, i.e. configures paints for future use. But if we take instead of paints and give the artist clay, then the desired color of clay will not be obtained by mixing clay (a laborious process). In this case, plasticine is inferior to paints.

Therefore, the use of a black box can be divided into two categories:
And I express an opinion to create, namely, intermediaries, and not “finished products”.
In the case of external libraries, “ready-made products” may be justified, but too much of a limitation may lead programmers to the devil's path. The goal of the intermediary, a convenient hidden box, of course, is to help abstract from the intricacies of the implementation, but also to give the opportunity to configure it as much as possible and, accordingly, to expand its use.
')
Principles to consider when creating libraries, black boxes for newly used code:
This concept can be called OOSILA.

PS: If the topic is interesting, then I will prepare examples using the principles of OOSILA.

UPDATE: hidden box => black box

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


All Articles