Three years ago, I learned C ++ and model programming. At that time, I only knew what was going on, but I knew it was CodeThis is invented after reuse. With it, you can write less code, because during compilation, he will generate corresponding types of functions, you don't have to write functions with the same functions for each type of data. However, I didn't have to study them in depth because I was too young to master the model.
Two years ago, I learned C #, understood what happened to polymorphism, and learned how to implement polymorphism. I realized that this was also invented for code reuse, you can also write a lot less code, because the type is automatically identified during running and the corresponding method is called, relying on the elegant and concise implementation of polymorphism, you don't have to worry about how complicated it is to write many large projects, so I am relying on the elegant multi-state hybrid work, so far I am still writing elegant polymorphism, but I always have a worry in my heart. Should we shirk the task to the runtime?
Currently, the concept of template metaprogramming has emerged in the field of model, and various design patterns rely on Polymorphism have emerged in the field of OO. One is code-level solutions, and the other is runtime solutions, both of them are brilliant, but I am wandering ..
In fact, C ++ also supports polymorphism, and C # also supports paradigm. In today's C # object-oriented design model, Microsoft's engineers are there. net framework2.0 container uses a large number of generic technology (ilist <>), while downplaying the multi-state technology (arraylist), and encourages you to use the ilist <> series of generic containers, in fact, it is not difficult to analyze the cause. When there are tens of millions of elements in the array, when calling a method for each element, the overhead caused by millions of polymorphism cannot be ignored.
Rational Thinking, paradigm and polymorphism. One is that tedious Code brings efficient operation, and one elegant code brings complicated implementation. We should choose object-oriented or paradigm rationally, rational view of template meta programming and design patterns.