Get to know object-oriented

object oriented

Object-oriented is also called OOP (Object Oriented Programming). It is not a grammar, but a programming idea and architecture. The meaning of an object refers to a specific thing, that is, something that can be seen and touched in real life. . In object-oriented programming, an object refers to a component in a computer system. In object-oriented programming, an object contains two meanings, one of which is data and the other is action. An object is a combination of data and actions. The object can not only operate, but also record the operation results in time.

1. Process Oriented (POP)

Process-oriented is to analyze the steps needed to solve the problem, and then use functions to realize these steps step by step. When using it, just call the functions one by one.
In javascript.

2. Object Oriented (OPP)

Object-oriented is to decompose the transaction into individual objects, and then the tasks are completed by the division of labor and cooperation among the objects. Object-oriented divides problems by object functions, not steps!

object-oriented features

1. Encapsulation: Pack repeatedly reused code blocks.
2. Inheritance: For example, there are object father and object son, and object son can inherit the properties and methods of object father.
3. Polymorphism: The same object shows different states at different times: for example, a mop, in addition to mopping the floor, the mop stick can hit disobedient children. Let’s give an example. For example, we need to eat
now
. , then according to the process-oriented thinking, it is:
1. Cook rice
2. Wash vegetables
3. Cut vegetables
4. Fry vegetables
5. Serve rice
6. Eat
while the object-oriented thinking is very simple:
1. Find a restaurant
2. Next Single
3. Eat

object oriented
Find a "restaurant" that can fulfill my needs, "produce" a meal, and then we get a meal through this "restaurant".
If there is this "restaurant", then we can use it directly; if not, then we can use it ourselves open a "restaurant"

Take the carousel as an example,
find a 'machine', this machine can produce products, this product is the carousel
If there is such a machine, we can get the carousel directly through this machine, if there is no such machine, we need to create a machine by ourselves

Process-oriented => face the process; focus on the process when programming, all functions are done step by step
Object-oriented => face the object; focus on the object when programming, all functions are created by the object

<script>
   * 轮播图
   //面向过程的思想
    创建第一个轮播图
    1. const banner = xxx
    2. const imgBox = xxx
    3. const focus = xxx
    4. const index = xxx
    5. function copyEle () {
      
      操作 imgBox}
    6. function setFocus () {
      
      操作 focus}
    7. function autoPlay () {
      
      操作 imgBox 和 index}
    //创建第二个 轮播图
    1. const banner2 = xxx
    2. const imgBox2 = xxx
    3. const focus2 = xxx
    4. const index2 = xxx
    5. function copyEle2 () {
      
      操作 imgBox2}
    6. function setFocus2 () {
      
      操作 focus2}
    7. function autoPlay2 () {
      
      操作 imgBox2 和 index2}

     //面向对象的思想
      b1 = {
      
      
         banner: xxx,
         imgBox = xxx,
         focus = xxx,
         index = xxx,
         copyEle () {
      
      操作 this 的 imgBox},
         setFocus () {
      
      操作 this 的 focus},
         autoPlay () {
      
      操作 this 的 imgBox 和 this 的 index}
         }
         b2 = {
      
      
         banner: yyy,
         imgBox = yyy,
         focus = yyy,
         index = yyy,
         copyEle () {
      
      操作 this 的 imgBox},
         setFocus () {
      
      操作 this 的 focus},
         autoPlay () {
      
      操作 this 的 imgBox 和 this 的 index}
         }
         *对象的 属性值不相同, 但是 方法 相似但不同
         *机器的核心 能够批量生产                
         *找到一个能批量生产对象的机器
         *并且是合理生产
</script>

Guess you like

Origin blog.csdn.net/weixin_48649246/article/details/127892356