C is a process-oriented language, and methods defined in the code are generally called all the time; in object-oriented languages (such as Java) or object-oriented languages (such as JavaScript), methods are defined on objects or classes. (ps: There is no clear explanation of classes in js). For example, there is a method to compare sizes:
In C language:
int compare(int num1,int num2){
return num1>num2?num1:num2;
}
//调用
compare(1,2);
In Java
public class Compare{
private int num1;
private int num2;
public Compare(int num3,int num3){
this.num1=num3;
this.num2=num4;
}
public int com(){
return this.num1>this.num2?this.num1:this.num2;
}
}
//调用
Compare cpm = new Compare(5,6);
System.out.println(cpm.com());
The above is a simple example to distinguish the different ways of thinking about the same problem between process-oriented and object-oriented. Although there is no outstanding point of being object-oriented here, in actual projects, there are many methods and a large amount of coding. In this case, classes can organize the code very well. For example, a user has different behaviors such as eating, walking, sleeping, and entertainment.
In C language, the implementation might look like this:
Obviously, object-oriented assembles the code structure very well, making it easier to understand. KuKe has an article about understanding object-oriented programming: Understanding object-oriented programming in this way, I hope it will be helpful to the subject's understanding of object-oriented programming
C is a process-oriented language, and methods defined in the code are generally called all the time; in object-oriented languages (such as Java) or object-oriented languages (such as JavaScript), methods are defined on objects or classes. (ps: There is no clear explanation of classes in js). For example, there is a method to compare sizes:
In C language:
In Java
The above is a simple example to distinguish the different ways of thinking about the same problem between process-oriented and object-oriented. Although there is no outstanding point of being object-oriented here, in actual projects, there are many methods and a large amount of coding. In this case, classes can organize the code very well. For example, a user has different behaviors such as eating, walking, sleeping, and entertainment.
In C language, the implementation might look like this:
In an object-oriented language, the implementation may look like this:
Obviously, object-oriented assembles the code structure very well, making it easier to understand. KuKe has an article about understanding object-oriented programming:
Understanding object-oriented programming in this way, I hope it will be helpful to the subject's understanding of object-oriented programming
You can read a Turing book called "This Object-Oriented Programming Book for Everyone".