Why do you use object-oriented programming? Why not process-oriented?

Source: Internet
Author: User
Write a paging effect I wrote it with 50 lines of code and then wrapped them in a function with a paging point and called the function, and I searched the Web with object-oriented pagination classes all 300 lines and could not understand why object-oriented with so much code to write? So isn't it nice to write in a process-oriented way? Why should we use object-oriented? It's hard and difficult to read.

Reply content:

Write a paging effect I wrote it with 50 lines of code and then wrapped them in a function with a paging point and called the function, and I searched the Web with object-oriented pagination classes all 300 lines and could not understand why object-oriented with so much code to write? So isn't it nice to write in a process-oriented way? Why should we use object-oriented? It's hard and difficult to read.

Shared girlfriend

    • Code industry overtime, there is no time to accompany the girlfriend shopping, travel, buy clothes.

    • Can't even afford to wait for her in kindergarten.

    • new GirlFriend()is not very simple.

    • It would be nice to have a good one, without having to coax her to be happy (maintenance).

Pnp

    • The girl's mind is hard to guess, the code that the big God next door can't read

    • The schedule is tight, the rhythm is fast, I just want to use the external configuration

Reduce casualties

    • Why did you change my code, you changed my code and you touched my wife, you know?

    • I'm not here. How does the plug-in function be implemented?

    • You're not going to tell me to plug it in?

The world is getting bigger, and you can do less

    • The time to fight alone has passed.

    • You have to work with people to get bigger things.

People read the poem, the machine eats the excrement

    • Why not just assemble it?

The value tradeoff of three kinds of efficiency

    • Operational efficiency

    • Development efficiency

    • Maintenance efficiency

    • Three kinds of efficiency, what efficiency is the cost, the combination of the mix to minimize expenditure?

    • The interpretation language is used in the trial phase.

    • The need to stabilize the demand for faster operation to the C development, saving the user's time

    • The world-class operational efficiency and constant demand is compiled, as the compilation is almost the ultimate saving of money for the world's people.

A huge conspiracy, plotting to create a world-class machine monster, but copying your code into his program seems too low.

If a thing is encapsulated as a function, it should not be encapsulated into a class. What you're encountering is a situation that happens to encapsulate a function.

Really suitable for object-oriented code, you break down into a function, you will find that the parameters are scattered, the transmission of trouble, find more trouble. That might as well have been written together in the form of classes.

For example, encapsulating an HTTP request requires passing URLs, methods, parameters, cookies, proxies, some assorted configurations, and so on. If you encapsulate a function, each function needs to have nearly 10 parameters, if encapsulated into a class, only need to pass the parameters that need to be set on the line, do not need to set parameters frequently, the constructor is assigned the default value. This is not convenient.

I think the upstairs talk is too complicated, but it's not that complicated. What are the advantages of object-oriented? Good maintenance, benefit the project maintenance extension. I do php, PHP process-oriented code is difficult to maintain, the use of object-oriented is not, in the case of complete documentation, maintenance expansion is very convenient. Although PHP's object-oriented sacrifices some of the performance, it is anthias to the maintainability of the project!

That's because you didn't develop a big project. In large project development, object-oriented programming will make your code less and more abstract and easier to maintain
You can look at this explanation on the Internet http://zhidao.baidu.com/question/2265557081512828548.html

This long story. For large programs, the advantages of the object-oriented approach are indisputable, but for a small program with a simple function, the two methods which are better are really not generalize.

But the 300-line code of the pager is likely to be richer than your 50 lines of code, and may be more configurable. Instead of saying that the function is exactly the same, the result is 50 vs 300 . If that's the case, then it's time to hit that guy's butt.

The side dish also ventured to answer this question which rises to the CS philosophical level.
First of all, there is no strong who is not the difference between the same, there is no high or low, or the Linux kernel that tens of thousands of lines of C code is not a high explosion?
The second is that the scale of the program is up, requiring multiple teams to be highly collaborative and easy to maintain, it seems, the object-oriented more suitable for some
Finally, whether it is the process or object-oriented, should be highly modular, abstract, easy to maintain the extension, or to dig a hole for themselves.

Against the non-black and white two-dollar thought

You can only say: Why object-oriented is universally used in most projects you've touched

The reason is that most programs deal with a large number of objects, the relationship is complex, if the simulation of the real-world way to organize code, easier to understand, and easier to maintain.

Do not object-oriented, because it is not a universal paradigm. The right one is the best.

Only process-oriented is not easy to reuse code.
Object-oriented facilitates the management of code and logic.

Easy to split the package module.
At the same time, declarative programming is much more intuitive than instruction programming when the framework is well-done.

In C language, the language level does not support C + +, Java that nature of object-oriented, but like PHP, Apache, Nginx, Linux these C programs, not the same can do good modularity? The two most representative new generation languages, such as go and rust, do not use the java/c++ type of object-oriented and exception handling, so there are two of these things that really are flawed. So, in PHP programming, don't blindly use object-oriented and exception handling in a dogmatic way like Java. From the Linux C library API and PHP built-in library functions can be seen in fact, its organization is not the Java class Library of the "object-oriented" way, but the use is very convenient, so that encapsulation into a function, the same can be implemented code reuse.

For a meal:
Process-oriented emphasis is on "eating", "people" is just a parameter. For example, Mysqli_connect generates a connection object as a parameter to the Mysqli_ series function.
The object-oriented emphasis is on "people" and "eating" is just an action. For example, new mysqli generates a connection object that can call the Mysqli class's methods and variables directly.
It is not always necessary to use object-oriented, which is convenient to use which.

Wang Yin treats object-oriented programming:
http://www.yinwang.org/blog-cn/2015/04/03/paradigms/
Wang Yin's insight into oop in this article mentions that object-oriented = Process + abstraction, while pointing out that the problem of full object-oriented leads to over-abstraction, instead of over-abstraction increases coupling.

"Object Idea" as the way of data access, there are some advantages.
However, "Object-oriented" (more "facing" two words), that is, the original good idea of rambling, far-fetched, played over the head. Many object-oriented languages claim to be "everything is an object", put all functions into the so-called object, called "method", the ordinary function is called "static method". In fact, there is very little need for abstraction, the use of a "method" embedded within an object and tightly bound to the data. Other times, you just want to express the transformation between the data, which can be expressed in ordinary functions, and it is simpler and more straightforward. Putting all the functions into the object is the cart before the horse, because the functions themselves are not objects, they are just transformations on the object. Most functions are independent of objects, and they cannot be called "methods". Forcing all functions into objects they do not belong to, all as "methods", resulting in an over-complexity of object-oriented code logic. Very simple idea, must go around many road bend can express clearly. Many people still do not know that their use of "object-oriented language" in many of the advantages, are inherited from the process-based language.

Most object-oriented languages lack the right mechanism to implement a class-a function. The Java language is an extreme, and it does not allow functions to be passed as data at all. You need to encapsulate all the functions into classes and call them "methods", but like I said, this is kidnapping. The lack of a primary function is the main reason why so many "design patterns" are needed in Java. Once you have a function, you will no longer need most of these design patterns.

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