C ++ Programming Paradigm

Source: Internet
Author: User

"C ++Talking about the three, "the devil once pointed outC ++OfProgrammingParadigm can be divided into ADT + PP, GP, ooThree directions.


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
: 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.