In the simplest sentence, what is object-oriented? What is the difference between him and the process? What are the benefits?

Source: Internet
Author: User
Maybe we are all in object-oriented programming, we really understand him, each programmer to object-oriented understanding is not the same, whenever people ask me why use objects without process, I always say that I do not have a good reason, I generally say, with the advantage of the object is that the code is concise, reusability high .... Tell me about your views and the summary of the years.

Reply content:

Maybe we are all in object-oriented programming, we really understand him, each programmer to object-oriented understanding is not the same, whenever people ask me why use objects without process, I always say that I do not have a good reason, I generally say, with the advantage of the object is that the code is concise, reusability high .... Tell me about your views and the summary of the years.

Personal humble opinion, for reference only, in order to inspire, to stimulate.

1. What is object-oriented?

Object-oriented is the combination of all methods (i.e. functions) and all attributes (i.e., variables) with a topic (the type is called a class, the entity is called an object), which is used to organize a program development method of the program.

2. What is the difference from process-oriented?

The process is organized by a single function, oriented to the process (function), while object-oriented is organized by a class/object that is stacked up to organize the program, oriented to the object (class/object).

3. What are the benefits of object-oriented?

When the scale of the software is constantly expanding, the process-oriented development of the program will encounter difficulties, on the one hand, difficult to cope with the pressure of the scale, later difficult to maintain, on the other hand, the code is difficult to achieve reuse, resulting in repeated coding (object-oriented through inheritance response).
Therefore, object-oriented development is a good solution to the difficulties of large-scale program development, the program organization is clearer and easier to maintain later.

Wang Yin treats object-oriented programming (Wang Yin has developed many projects, including his Yin language) using Java:
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.

The most important thing in programming, in fact, is to allow the writing of symbols that can simply model the actual or imagined "world". The most important ability of a programmer is to intuitively see the correspondence between a symbol and a real object. No matter how cool the language or paradigm looks, it is not a good language or paradigm if it has to be around bend to express the programmer's model.
(End of quote)

Individuals also feel that object-oriented is not wrong, the wrong is "full" object-oriented, because sometimes do not need to adopt object-oriented, completely object-oriented is too much to cut. With PHP's mysqli extension, it provides both object-oriented and procedural uses. Object-oriented is new mysqli () Creates an object and then makes it easy to invoke methods and members. The process is a series of functions that use the prefix mysqli_. In this scenario, the individual feels that new mysqli () is indeed more appropriate. However, for some scenarios, such as PHP's built-in parsing URL function parse_ URL, personally feel that there is no need to use object-oriented, if a URL to deal with the class, put Parse_url into the inside, it is too superfluous, the simple problem is complicated, as a function of a very clear function, directly provided to the programmer call, obviously very friendly.

Initiate

Q: What is Object-oriented?
A: A programming paradigm, in contrast to a process, represents an abstraction of the real world as a unit of data (objects).

Q: What is the difference between object-oriented and process-oriented?
A: Use the program to describe "I eat". Process-oriented notation: eat(I, food) Object-oriented notation: I.eat(food) . The most intuitive difference between the two is that the program is organized differently, the process-oriented program takes actions (functions) as a building block, and the real-world description is done by invoking other functions in the function. Object-oriented is to use data (noun) as the core, through the message passing between objects to build the program.

Q: What are the benefits of object-oriented?
A: Object-oriented more in line with human cognition of the real world, the concepts of abstract "class" and concrete "object instance" can be well understood from childhood, such as "human" is an abstract class, and "Zhang San" is a "human" class Object. There are three main characteristics of OO: encapsulation, inheritance, polymorphism, the ability to avoid naming conflicts and implement code reuse, which is advantageous for building large programs.

The above answer is very clear.
Object-oriented is the rational use of "class".
Process-oriented is the rational use of "function".
Benefits? Reduce duplication of code and increase maintainability.

When I was studying Java with a horse soldier teacher in college, he said:

Process oriented
Car start is an event and the car arrives at another event. When you are in a program, you are concerned about an event, not the car itself.
Write the starter car program.
Prepare the car arrival procedure.
If the car breaks down, write a "repair car" program.

Object oriented
First select the Action object--the car. In the process, the concern is the car itself, let the car to complete each action.
Order the car--start.
Order the car--to the station.
If the car breaks down, order the car--fix it.

It is clear that object-oriented is the closest programming idea to human thinking.

In my view, the biggest advantage is:

More conducive to human thinking

Object-oriented definition, a lot of online search. It is true that every one of us is using it, but few have ever thought about why.

In fact, the grammatical aspect is that object-oriented is only a process-oriented syntactic sugar . Inheritance, polymorphism, and so on, can be completely simulated with process-oriented, just simplified difference.

The existence of object-oriented is certainly valuable. True, process-oriented can also be used in software engineering, but why is it not respected? The reason is: bad thinking .

Human beings are more willing to use the idea of contact to see the problem, because it is closer to life experience, and object-oriented can be a good embodiment of this thought.

To break things down into realization, this is the brain of the machine; It's human brains to connect things together as a whole.

The above said is very good, I also come to gather a lively ~
Simple to a sentence: (according to the requirements of the main title)

    1. What is object-oriented? The object is a data + operation.

    2. And what is the process-oriented difference? Object-oriented is more concerned with data, while process-oriented is more concerned with operations.

    3. What are the benefits? Object-oriented makes it easier to encapsulate data, encapsulate operations, extend (inheritance mechanisms), and provide lighter interfaces-polymorphic and Ducktype

Upstairs said is very good, but said a word to say clear ...

To me, object-oriented is better than process-oriented: Human language is largely object-oriented. (at least Chinese and English are.) I'm going to have two of these. )

If you want to summarize, then it is: object-oriented is the problem of modular, process-oriented is the problem of programmatic

Old programmers, C # JAVA C + + py have gone through, now love node. So many years of feeling is that OO is actually a modeling method, simply said that you are how to understand the world these business, OO is just one of them. More contact with different ideas, only to understand the differences, do not dwell on the theory.

The philosophical thought of piecemeal

Give me a chestnut.
To achieve a small function of the e-commerce website is called "Delete goods"
If object-oriented: The possible idea is---"Delete goods" is a way to delete a product, then add a method in the Product class
If it is process-oriented: the possible idea is to---"Delete goods" is 1, to determine the user login status, 2, to determine the user rights, 3, the operation of the submitted database table operations, 4, return the results;

Don't know what to say don't understand, I have not learned object-oriented programming, small white Understanding ~ ~ ~

Take a laptop.

process thinking: ask your friends around--online for quote--to the nearby computer city to buy yourself;
Object thinking: find someone to give him money, let him get a laptop for you.

OO is better suited to encapsulate data and its corresponding operations, and to hide implementation details from the outside.

Can be encapsulated on the package

I have written java,node, which can be said to be a transition from object-oriented to object-oriented + process oriented. From my personal experience, the process is more rapid and simple, more close to the way people solve things. For example, the store sells a ball, the process-oriented idea is to take the total number of balls, minus one, then save, and add an order. This way of thinking is more similar to the real business process. So called process-oriented.

But object oriented is another way, it is first to put these entities are abstract two classes, balls, orders. The implementation method is then provided. For example, the class of the ball has method sell, calling this method will reduce the total number of balls by 1, and then call the order method Add, add the order. The overall idea is to design the interface and interaction of the class first, and then simply send the message to the relevant class as soon as the business occurs. Here, we just need to call the Sell method of the ball. As for, it how to place orders, order prices, we do not care.

It can be seen that the object-oriented approach is conducive to business logic cohesion, as long as the design of the interface, it may be a long time without changing the way the class is communicated. is always called the sell of the ball. When the price of the ball changes, or there is a promotion, we only need to modify the sell implementation, or for temporary promotions, to achieve a ball of sub-class, such as called Promotional ball. In this way, the maximum stability of the structure can be ensured. But conversely, if you really want to change the structure, the cost is relatively large. And in order to ensure the stability of the structure, the upfront design will also spend more resources.

Process-oriented advantages are also in this, although dealing with complex business is not a strong point, but rapid development, change the cost is relatively small. Ideal for development where complexity is not high or moderate, business content is changeable.

Above.

Now we should discuss OOP and AOP.

Encapsulation, inheritance, polymorphism.

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