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, Includes not limited to the following points: first, greatly increased the amount of code, including a very large number of redundant code for the process language, programming requires which variables and methods to write only these variables and methods, and for the object-oriented language, every time you want to use whatever you want to write a class first, And each class must have independent variables and methods, which will cause the problem may be very simple and a lot of class code, in order to solve this shortcoming, inheritance will appear, 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 object-oriented language is all objects, we must use an object to create another object in order to use its internal methods, so that these objects are interdependent, in order to eliminate these dependencies, We can put all the code of the created object into one object, and the other object will get the desired object dynamically 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, slow running all the objects in Java are present in the heap, and the object is built to access the object slowly, Java put the object in the heap, the object's reference to the stack, by reference to call the object so that the access speed is slightly faster, the JVM 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. Equivalent to Windows magnetic www.yuheng119.com disk defragmentation.
  
Loss of flexibility object-oriented language code is inflexible, inheritance does not run-time dynamic, 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. Object-oriented language has been advocated by the combination of more than the idea of inheritance has produced a lot of design patterns, these design patterns through the combination and the wonderful use of polymorphism greatly increased the flexibility of the object-oriented language www.yixingsyle.cn words.
  
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.

Original link: http://blog.sina.com.cn/u/6145394306

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.