The disadvantage of object-oriented language

Source: Internet
Author: User

When we first approached Java, we learned that the four basic features of object-oriented language are abstract inheritance encapsulation polymorphism and a lot of object-oriented language advantages including code reuse, permission control, easy to expand, high development efficiency and so on, in fact, object-oriented language from the date of birth has been accompanied by many defects, This includes not limited to the following points:

One, greatly increased the amount of code, including a very large number of redundant code

For a procedural language, which variables and methods are required for programming, and for object-oriented languages, you write a class every time you want to use anything, and each class has independent variables and methods, which can lead to a lot of class code that can be a simple problem. In order to solve this shortcoming, inheritance appears, inheritance can let classes and classes can share code, to a certain extent, reduce the amount of code.

Two, the object and the object interdependence, the coupling is too high

Because everything is an object in object-oriented language, we must use an object to create another object in order to use its internal methods, which causes the interdependence of these objects, in order to eliminate these dependencies, we can put the code of the creation object into one object, Other objects are dynamically getting the desired object by invoking the object's method, which is what we call the factory pattern. Further, instead of using a factory, we can write a plug-in that dynamically "plugs" the objects we need at runtime, which is dependency injection, which is control inversion. This plugin is equivalent to the spring IOC.

Third, the operation speed is slow

All of the objects in Java are present in the heap, the object is built to access the object is very slow, Java put the object in the heap, the object's reference to the stack, by reference to call the object so the access speed is slightly faster, the JVM GC garbage collection mechanism, will automatically clean up the garbage object, and put all valid objects together in the heap, so that when you create objects, it's faster to look for empty heap memory. Disk defragmentation equivalent to Windows.

Iv. Loss of flexibility

Object-oriented language code is very rigid, there is no runtime dynamics of inheritance, but Java's polymorphic mechanism, which differs from the process-oriented approach to late-binding method, at run time to determine the specific invocation of which method to a certain extent increased its flexibility. The idea that object-oriented languages have been advocating a combination greater than inheritance has spawned many design patterns that have greatly increased the flexibility of object-oriented language through the marvelous use of combinations and polymorphism.

To sum up, in fact, in our learning process can see the object-oriented language there are many excellent places, but there are some shortcomings, and we have been trying to do all kinds of ways to compensate for these shortcomings, through a number of mechanisms to make object-oriented language more and more to improve.

The disadvantage of object-oriented language

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.