I think the concept of "encapsulation" is the most basic concept in object-oriented thinking, which is essentially by putting together a bunch of related functions and a bunch of objects, having functions as operational channels, and internally using variables as raw materials. It is left to the external programmer to operate without exposing the specifics of the execution. A typical example of a book is a car and a light bulb: you don't need to know the engine principle of different cars, you can run on the accelerator, you don't need to know that your light bulb is the kind of bulb, and the switch will light up. We all intuitively think this is a great thing, right?
But sometimes it feels like there's something wrong with the object-oriented language, I vaguely feel that encapsulation may not be as good as we intuitively think, that is, object-oriented is not as good as our intuition, though it has been popular for many years.
Functions are doing things, they have inputs, they have execution logic, they have outputs. The data structure is used to express the information, either as input or as output.
The two are essentially completely different things, object-oriented thinking put them together, so that function is limited to a certain area, so that although the operation can be well categorized, but this classification method is based on the "sphere of action" to classify, in the real world can, but in the program of the world, some inappropriate.
There are several reasons for improper:
In parallel computing, because the execution part and the data part are bound together, this makes the scheme constrain the degree of parallelism. In order to better achieve parallelism, industry engineers found a new idea: Functional programming. Use functions as data to ensure that the functions performed are correct in timing. But don't you think, as long as the data expression and the execution part separate, form the pipeline, this can not be very convenient to increase the number of parallel?
Let me give you an example: when the data and functions are not separated, the procedure executes as follows:
A. Function1A. function2A. Function3 finally got processed a
When in a concurrency environment, assume that so many tasks arrive at the same time
A.F1()-A.F2()-A.F3()Finally get the processedAB.F1()-B.F2()-B.F3()Finally get the processedBC.F1()-C.F2()-C.F3()Finally get the processedCD.F1()-D.F2()-Df3 () finally get processed de f1 () -> e. F2 () -> e. F3 () finally get processed ef. F1 () -> f. F2 () -> f. F3 () finally get processed f ...
Assuming that the number of concurrent numbers is 3, then complete a number of tasks similar to the one above, which is the timing.
|Time|1|2|3|4|5|6|7|8|9|10|11|12||------|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----||A|A.1|A.2|A.3|||||||||||B|B.1|B.2|B.3|||||||||||C|C.1|C.2|C.3|||||||||||D||||D.1|D.2|D.3||||||||E||||E.1|E.2|E.3||||||||F||||F.1|F.2|F.3||||||||G|||||||G.1|G.2|G.3|||||H|||||||H.1|H.2|H.3|||||I|||||||I.2|I.2|I.3|||||J||||||||||J.1|J.2|J.3||K|| | | | | |