Bind early or later. Bind early or later
Binding refers to the process of establishing an association between objects and their types.
Early binding means that the object is associated with its type during object declaration.
Late binding refers to ourCodeAt runtime, check whether the object provides the required methods and attributes.
Many people say that C # and Java are bound early, while JavaScript and Python are bound late. In fact, this is not all true.
On the one hand, C # and Java are strongly typed, And the type is described during variable declaration. Here, of course, they are bound early, so we can enjoy the convenience of code prompts in IDE, because IDE can know what type, method, and attribute of your object through your declaration, and then prompt you, at the same time, it can also help you check many types of conversion errors during compilation.
On the other hand: whether C # and Java are implementing a very important feature: During polymorphism, they are all bound late. For example, your parent class defines the virtual method, this method may be reloaded in your subclass. What subclass do you use is unknown During Variable declaration, the C ++ compiler will add a pointer to these classes during compilation. The Pointer Points to a virtual table, and there are real functions in the virtual table. This is a late binding.
Early binding has the following advantages:
- Compilation Efficiency
- Code prompt (Code intelligence awareness)
- Compile-time type check
Late binding has the following advantages:
- No declarative type
- The object type can be changed at any time.
Some materials
Http://inmyheart.bokee.com/630168.html
Http://community.csdn.net/Expert/TopicView3.asp? Id = 5647919