Advantages and disadvantages of Object-Oriented Programming

Source: Internet
Author: User
If you are a programmer, 90% of project leaders will ask you during the interview.

"How do you know the advantages and disadvantages of object-oriented programming"

Let's first look at what others say.

===================================== Understanding of other people's OOP ==================== ============================
Object-Oriented Programming (OOP) is a computer programming architecture. One basic principle of OOP is that a computer program is composed of a single unit or object that can act as a subroutine. Oop has achieved three main objectives of Software Engineering:Reusability,FlexibilityAndScalability. To achieve the overall operation, each object can receive, process, and send information to other objects. Oop has the following concepts and components:

Component-a unit formed by data and functions in a running computer program. components are the basis of modules and structures in OOP computer programs.
Abstraction-the Program has the ability to ignore some aspects of the information being processed, that is, the ability to focus on the main aspects of information.
Encapsulation-it is also called Information encapsulation: to ensure that the component does not change the internal status of other components in an unpredictable way; only in those components that provide the internal state change method, to access its internal status. Each type of component provides an interface for contacting other components and specifies the method for calling other components.
Polymorphism-the reference and class assembly of components involve many other different types of components, and the result of referencing components must be based on the actual call type.
Inheritance-allows sub-components to be created based on existing components, which unifies and enhances polymorphism and encapsulation. Typically, classes are used to group components, and new classes can be defined as extensions of existing classes, so that classes can be organized into a tree or mesh structure, this reflects the versatility of the action.

Because of abstraction, encapsulation, reusability, and ease of use, component-based programming has become particularly popular in scripting languages. Python and Ruby
This is a recent language. It fully adopts the idea of OOP during development, while the popular Perl
The scripting language has gradually added new object-oriented functional components since version 5. Use components to replace "reality" entities into JavaScript (ecmascript)
The reason for the popularity is that it is demonstrated that appropriate combinations of components can replace the HTML and XML Document Object Model (DOM) on the English site ).

Advantages of OOP: Make People's programming closer to the real world. All objects are Assigned attributes and methods, and result programming is more humane.

Oop disadvantagesFor C ++, C ++ makes C ++
In implementation, we have to sacrifice performance, sometimes even fatal (
Attributes of all objects are indirectly referenced by multiple built-in pointers, which is one of the main reasons for their performance loss. However, the limitation of the author is that VC ++ has not been used.
The external object-oriented language is not very certain. Haha, someone laughed... ).

Today, with the rapid development of computers, you may say that a little bit of performance sacrifice is no big deal. Yes, from an object-oriented perspective, the programming structure is clearer and more complete, data is more independent and easier to manage, and the sacrifice of performance can bring so many benefits, is there no reason not to make a steady profit?

However, in some special scenarios where the speed requirement is extremely high, for example, if you are using a telecommunications exchange system, more than one million people will exchange phone calls at the same time every second. If, every data exchange process is an object, so the total performance loss will be astronomical !!


Or this example is not close enough. Let's take another example. If you are employed by a game design company, the boss hopes that the game can be made with more computer users, and the frame of the game can run every second.
More and more bullets and explosives can be more and more gorgeous. Then, you will find that C ++
This will cause your program to become clumsy and unable to meet your needs, unless you need your game to run on the Pentium 4 machine (if not, and you insist on using C ++
So reduce the power of the main character's gun ).

If you are a stubborn person and you say you don't believe that OOP will cause performance loss, then I remember seeing VB and VC
The article on execution efficiency is about the use of MFC, the execution efficiency is even lower than that developed by VB. Please verify: if you are using pure C
The language syntax is much faster than what is compiled in VB (the gettickcount function can be used to check msdn. If you want to be more accurate, you can use
Queryperformancecounter function ).

============================================================ ======================================

Original article: http://www.itisedu.com/phrase/200603050951565.html

Your own understanding of OOP:

1. Advantages

A reusability is conducive to the development speed. If you want to develop a function and find it difficult to implement it, another technology can solve this problem.
The advantage is brought to play.

B. encapsulation/Abstraction: clear structure, standard standardization, easy to understand, more readable

C. inheritance is easy to expand, and it is easy to develop functions suitable for you without changing the large framework.

2. Disadvantages

A. The execution speed is reduced.

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.