The underlying mechanism of C++ polymorphism

The most hard working in using a computer language is understanding the underlying mechanism of the tricky syntax and semantics and facilities. For example, in C++ programming practice, you must know what and how the compiler had done to implement the polymorphism for the surface magic C++ polymorphism. However, the compiler hides everything. Then you read and know the tricky mechanism about how, key data structure in C++ world, virtual functions table, which contained the addresses of virtual functions of the instanced objects of hierarchical classes and is used to relate and find the function with same call signature but located in different class scope. Both base class and derived class modify the table to implement the dynamic binding. This is a very tricky hid process for really mastering the language. 

Therefor facing modern high-level language flexible facilities provided for easily programming and building complex concepts system, we must insist on the belief that is we must realize the underlying fixed mechanism clearly and could code much for better understanding and mastering the language. Then this belief becomes a standard which can identify the elegance of the code and coder. Even, the pattern or style that is using the fixed mechanism to implement the flexible facilities can be learned and used everywhere.   

Abstraction is about the point or focus of concerning which concentrates on some aspects. What the real concerning or caring of human is the matter, the opposite is the form. Abstraction is the matter. The matter can exist and maintain same with many forms which change and vary and mutate. In OOP field, the matter is the data abstraction, interface, meta-data, otherwise, the relative forms are different implementations of same interface. The interface is the concern and abstraction of forms which vary much. That is the theory of polymorphism and multi-forms. 

The observed feature of object is related with the observer. This is true in OOP, even, the observer would influence and determine the feature, the result is one object can have many different types(different observers). The properties of object is decided by type which is used by program. 

It is not difficult to express the genericity and difference among concepts in natural language. However, demonstrating the sameness and variation of concepts in formal language needs a little tough and tricky language facility. An easier way is that labeling the related concepts with same symbols and different parameters. In C++, function polymorphism including function overloading and function template and dynamic member function overriding is the facility to express the range of between genericity and difference among functions born with the same name. Even, with these facilities, mechanism can do something and new concepts could be created and expressed. In C++, the function template facility is the new powerful language facility to implement the most genetic functioning concepts. Otherwise, the class template is the facility to implement the most genetic class concepts as well as tool to develop static class polymorphism.     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值