"C ++Talking about the three, "the devil once pointed outC ++OfProgrammingParadigm can be divided into ADT + PP, GP, ooThree directions.
1,ADT + PP
ADT: abstract data type; abstract data type
PP: Procedure programme; process-oriented programming paradigm
ADT + PP is the process-oriented programming paradigm + abstract data type. You can understand it as the predecessor of C ++: Class C.
2. GP
GP: Generic programming, GP (generic programming, generic programming) is called another revolution in programming ideas. However, the discussion on GP is generally based on the C ++ language.
Generic programming (GP) is a programming technique based on parameterization: You can use a type to parameterize another type (for example, the element type of the vector is determined by parameters). The algorithm can also parameterize another algorithm (for example, using the comparison function to parameterize the sorting function ). GP aims to generalize and optimize useful algorithms or data structures as much as possible.
GP is much more flexible in some aspects than oop. In particular, it does not depend on the hierarchy. For example, there is no hierarchical relationship between int and string. In general, GP is more structured than oop. In fact, GP is often called "parametric polymorphism", while OOP is often called "ad hoc polymorphism ". For C ++, GP resolves all the names during compilation; it does not require any dynamic (runtime) scheduling. Therefore, GP occupies a dominant position in the field that has high requirements on the operation efficiency.
Note that GP is not a panacea. In many cases, programs do not require parameterized polymorphism, but require runtime scheduling (OOP ).
3. OO: Object-oriented Programming
Object-oriented programming (OO), object-oriented Programming (OOP), and object-oriented programming language (oopl) are defined in a variety of ways. For more information, see
Why is C ++ not just an object-oriented language?. I wrote there that the programming style of OOP originated from Simula (about 40 years ago !), It depends on encapsulation, inheritance, and polymorphism ). In terms of C ++ (and many other languages originating from Simula), oop refers to programming using classhierarchies and virtual functions, in this way, you can operate on various types of objects through refined interfaces, and the program itself can also perform function incremental extension through the derivation.
Note that OOP is not a panacea. Do not simply equate "Oop" with "good ". If there is no inherent hierarchical relationship among the basic elements of your problem, the class level and virtual function will not be helpful to your code. The advantage of OOP is that the class level can effectively express many problems. The main weakness of OOP is that too many people try to solve problems by using the hierarchical mode. Not all problems should be object-oriented. You can also consider usingCommon class(Plain
Class ),Generic programmingAnd independent functions (like in mathematics, C, and Fortran) as solutions to problems.
Multi-model Programming
Multiparadigm programming is a fancy way to "program in multiple styles and do everything you can. For example, you need to use object-oriented programming when you are running the time zone to divide the object type, while you need static type security and the pursuit of execution efficiency to use generic programming. Obviously, the main power of multi-dimensional programming is embodied in a program that uses multiple types (programming styles, it is difficult to create a system with the same effect by using a variety of languages that support different models. The most striking effect of multi-model programming is that, if you enable close collaboration between technologies from different models, you can write code that is more refined and more maintainable than a single-model program.