Home  >  Article  >  Backend Development  >  javascript - Does object-oriented need to be process-oriented first? What are the similarities and differences with componentization and modularization?

javascript - Does object-oriented need to be process-oriented first? What are the similarities and differences with componentization and modularization?

WBOY
WBOYOriginal
2016-07-06 13:53:351167browse

Dear seniors, do we need to be process-oriented before being object-oriented?
In object-oriented programming, how to quickly sort out and locate the logical relationships between objects?
Where is object-oriented flexibility reflected?
Object-oriented is suitable for heavier development. Does writing small effects such as carousels in ordinary js still require object-oriented?
What are the similarities and differences between object-oriented and componentization in JavaScript, and what are the similarities and differences between JavaScript and modularization?

Reply content:

Dear seniors, do you need to be process-oriented before being object-oriented?
In object-oriented programming, how to quickly sort out and locate the logical relationships between objects?
Where is object-oriented flexibility reflected?
Object-oriented is suitable for heavier development, right? Does writing small effects such as carousels in ordinary js still require object-oriented?
What are the similarities and differences between object-oriented and componentization in JavaScript, and what are the similarities and differences between JavaScript and modularization?

The problem involves too much, so let’s talk about it in a provocative way.

Process orientation in software development is absolute, program = orderly execution of process. In fact, there was no concept of process-oriented before, but after the emergence of object-oriented, in order to distinguish this method from the previous method of using functions to organize code, then the code organized using functions was called process-oriented. (Just my personal opinion)
Object-oriented is a way of organizing code. It has various benefits. Just search it yourself.

As can be seen from the above, process-oriented or object-oriented refers to the organization of code, while componentization and modularization refer to the organization of functions in the project, so the two have nothing to do with each other.

During microelectronics maintenance, if a module is damaged, you only need to replace the module. Therefore, extending to software development, modularization means that the code is clearly encapsulated and has a definite scope rather than affecting the entire project.
The various tools used daily are actually based on the idea of ​​components. Components will be frequently and widely reused without being restricted by the scope of the module.

As for your various questions, the final answer remains the same: it depends on the needs, just meet the requirements. Note that code readability, flexibility, and maintainability are part of the requirements, which are very, very, very important.

Very simple comparison:

<code>//最简短的代码是1行
alert('Yeah');
//最简短的函数要4行
function f() {
    alert('Yeah');
}
f();
//最简单的对象要7行
function o() {
    this.f = function() {
        alert('Yeah');
    }
}
var obj = new o();
obj.f();</code>

There is a lot of design content. Object-oriented and process-oriented are two different ideas, but there must be a process in it to elicit objects. Process-oriented is analysis, and object-oriented is construction. Componentization and modularization are the products of object-oriented and process-oriented (personal opinion)

Process-oriented and modular, these are necessary for writing programs.
Procedure orientation is easy to understand, all programs are processes
Modularization is also easy to understand, that is, to isolate the parts that can be independent in the program process, ensuring the readability of the program, and regardless of control It is more concise to fix errors or troubleshoot bugs. I believe that people who have learned C and then want to learn C will think about one question, that is, what is the difference between structures and objects? They can both play a role in modularizing the code. If you say that structures have no methods, I would say that structures have no methods. You can also define function pointers. You said that structures do not have this pointers. In many cases, I think there is no difference between this pointers and syntactic sugar. As for constructors and other things, it is simpler and structures can do it.

What I want to say is that the most important thing about object-oriented is inheritance
When I was in school, the teacher would give an example, such as human as the parent class, and then the teacher class and student class can be derived, and the student class can in turn derive boys. Class, girl class.
However, this example is very nonsensical and poor. Students will not derive such a lot of useless classes when doing coursework.
And in fact, most developers will not randomly derive weird classes, which will lead to poor readability of the program.
So where is class inheritance usually used?
Give an actual example

I recently wrote React, and the beginning of each component with state is written like this, class XXX extends React.Component{}
Here, as long as I inherit React.Component, my component will have render method, which can display class content on the web page; my component also has a componentWillReceiveProps method, which can execute the process I want when the component receives new data. I don't have to worry about how these things are triggered, but I know that they will definitely be triggered. This is the ability obtained by inheriting a class.

Similarly, if you use VS to develop a WPF window program or something, your form will also inherit a class from the Microsoft basic library, so that your form will have basic click responses, drag and drop, etc. Function, you don’t have to write it yourself.

There are various frameworks, everything is the same. If you inherit the basic class of the framework, you can get the functions provided by the framework.

When object-oriented is mentioned in textbooks, software engineering is usually mentioned, as well as the book "The Myth of the Man-Month". Software engineering and object-oriented are all things that programmers summed up when developing software on a large scale. , similar to building a house, lay the foundation first, and after the foundation is laid, I will build more functions on top of it. Therefore, if you just follow the textbook and do some exercises when you are a student, you will not be able to understand the many meanings of object-oriented

Haha. What a great question. I’ll mark it first and I’ll take the time to answer it later

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn