Reference
In the C ++ programming language 3rd (Bjarne stroustrup, 1997:
Page 1:
Objects of some user-defined types contain type information.
Such
Objects can be used conveniently and safely in contexts in which their
Type cannot be deter-mined at compile time.
In the previous article, "fan Feng ignition: Also on the meaning of Bjarne stroustrup" Object-based ", and B4 master"ArticleI don't think its logic is very clear, because the specific meaning of "determining during compilation" in the arguments in the discussion and reply is everywhere without being emphasized. The premise is: "Compilation determines" including "Determination of the range (possibility) of the type and creation logic (Rules, first, the "range of types" must be only available for compilation. Second, the creation logic is determined at compilation as a rule, which is then classified as "determined at compilation ", there is no space for determining the type during the "running" Operation on the premise of this angle and static language. In this way, the conflicts are concentrated between the "pre-compilation decision" and "compile decision". Some problems are discussed on this premise.
In our daily understanding, although the possibilities and rules are fixed, the actual type still needs to be run, and the results can be classified as "confirmed at runtime. From this perspective, if we clarify the meaning of "cannot be determined during compilation", it will include two types: "pre-compilation limitation" and general "RunTime confirmation. Under this new premise, the original saying of the master is chewed again, and there is a completely different view that contains it. The point of view to be described in this article is still from the Bjarne stroustrup statement, but it is quite different from the previous one.
This article does not mean that the original words of Bjarne can be understood in two ways: I dare not easily misinterpret the expression that masters oppose the object-based feature. This is not because he is a master, but because he expresses what is, has nothing to do with right and wrong, and has nothing to do with understanding and understanding.
Let's talk less, as described in the above section:
First, discard the "type range and creation logic" from the definition of "Compilation Time Decision ". Or the following pseudoCode:
Object O;
If (Case ){
O = New Book ();
}
If (Case B ){
O = new dog ();
}
O. tostring ();
It turns out that we areThe range and creation logic of the types at the time of compilation are fixed, so that the type range and various possibilities of the objects referred to by O are fixed at the time of compilation.;From another perspective, I think that because the creation logic is executed at runtime, the possibility and rules caused by the unchangeable creation logic are fixed, and what O is counted as runtime?.
Or the following pseudo code:
Module 1:
Book B = bookfactory. instance. Create (parameters determined by the end user );
B. Open ();
B. dosomthing ();
Public class bookfatory {
Public static bookfatory instance {
Return (bookfactory obtains the instance according to the configuration file );
}
Public abstract book create (string PARAM );
}
Module 2:
Public a special bookfactory: bookfactory {
Public override book create (string PARAM ){
Switch (PARAM ){
Case "parameter ":
Return New Textbook ();
Case "parameter B ":
Return new graphbook ();
Default:
Return new defaultbook ();
}
}
}
As mentioned aboveDifferent possibilities and rules of the actual types caused by fixed new types of compilation in Module 2 and creation logic are included in "determined during compilation ".;Now we take the process of creating a logical execution to obtain a unique result as the actual type of execution at the runtime.(Do not discuss bookfactory, because it is beyond the capability of static languages ).
In turn, let's look at what the master's words have become? I personally understand this:
Note that the words to be deepened are different from those in my previous article. At the same time, the last sentence about "Object-based" is removed.
Some user-defined type objects contain the type information (Cause).
These objects can be conveniently and securely applied to context (Consequence),(Although) Their types cannot be determined during compilation.
It is precisely because the book type is defined that it provides sufficient type information (while hiding other unwanted information) that makes it easy for us to secure in context, these objects are easy to use, and the actual type of the object will be determined after it is run to the creation logic, for example, in the above pseudo code, after obtaining the user input. In this wayBoth the benefits of limited types and the ability to change.
That is to say, it is a good thing to use it based on a certain type of object! This is not involved in the original debate. I originally planned to discuss it in the future:How can static object-oriented users help us by limiting (rather than scaling) what we can do?. All in all, the context and implicit understanding are different. This sentence can show a variety of meanings. It seems that the words of the masters have a characteristic, that is, whether they are single-handed, there is a context, no matter how interesting you are, in any case, Khrushchev is always right. If someone else is a master -__-.
The difference between the two definitions of "determined during compilation" is that, the preceding article emphasizes that the creation logic is the compilation result that causes fixed types (optional types and selection methods are all dead ), this article emphasizes that the creation logic produces results during execution (the actual type is optional based on certain rules at least in the possibility of compiling results ). Therefore, in this article, you can allow "RunTime confirmation" of static languages ". It should be noted that, if you agree with my previous article, or
In the first interpretation of stroustrup, you must understand the meaning of "determined during compilation" and the changes caused by the differences in this article. Otherwise, understanding will become a misunderstanding.
Narrow down the meaning of "depends on the Compilation Time", so that the type of the compilation result is different during execution (although these logics are determined during compilation) after being included in the "RunTime decision", how do we express the concepts we mentioned in the previous article? As follows:Do not change your object to an object in the "pre-compilation confirmation" format, thus losing the ability to determine its specific type at runtime Based on the Compilation results of the available type range and creation logic.
To use deerchao as a master, deerchao expresses the usage of objects in the "pre-compilation confirmation" format, which is based on objects, so it is not object-oriented. However, putting forward this understanding above does not mean that I have no difference with deerchao: in the previous article, I also ask you to pay attention to the "often" term in the master's original article, it should not be said that "Object-based" cannot be "Object-Oriented" at the same time (outside often). My idea is that it depends on the specific design needs.
Considering the "Bounce" feature of this article,
It should be noted here that I have no intention of misinterpreting the meaning of the master, but I hope to highlight some points of view by looking for topics from different special perspectives. At the same time, I would like to make a reminder that, no matter what you say to something or a master, you should not always make a decision.
After this wave is complete, I will re-organize the two understandings of the same sentence Bjarne stroustrup into an article and "do not set the type of death" in the previous article ", this topic is connected to the topic "appropriate definition type" to highlight this topic: "You must define the type function properly, but do not design or implement it as unchangeable. "This is a problem that is difficult to solve in design, but it is too easy for many people to handle.
P.s.
This article is irrelevant to the previous one. In order to prevent unclear concepts, it has been edited for many times and started to hurt, seeing the last editing time indicated by the system, we can see how terrible the problem of splitting is, but this is often another wild way for me to explore things, I hope I can be inspired by my brother who has similar ways of thinking.
I will not post this article to the home page for the time being. First, I will reach the purpose of the previous Article: To deepen my understanding of the situation "CONFIRMED BEFORE compilation" and "do not set the dead type;
Second, when someone does not borrow any tool, the code "determined during runtime" in the meaning of "Compilation Time Decision" in the previous article will be sent up and said :). This article is easy to understand, so that in the original context, the content of "Compilation Time decisions" and "RunTime decisions"
The previous discussion is a mess.
My estimation now is that the Code sent by Xu's brother is either "determined during compilation" in the context of the previous Article (for example, we can clearly see that the type range and creation logic are determined at the Compilation Time.
Or directly or indirectly using some capabilities from. NET Framework. Or I ignored other restrictions and didn't add them. God knows, and then I will talk about it later :). However, no matter how many times Bjarne stroustrup mentioned above, I can't see that the master has this meaning:
"What Do masters mean?
During compilation, the types of these objects cannot be determined through context.
So thisProgramIt is called object-based"
If the word "Object-based" contains the meaning of "not Object-Oriented" in deerchao, Comrade Alexander, Xu shaoxia, and more people. Because most dynamic languages can easily embody "encapsulation", "inheritance", and "polymorphism", they can even practice the principles of "interface-oriented programming, I can only stand on the other side.