zoukankan      html  css  js  c++  java
  • js面向对象总结

    初识面向对象
    一、面向对象和面向过程的区别
    面向过程
    程序 = 算法 + 语法                         
    弊端:1.问题规模增大,无法控制后期代码
              2.代码的复用性低
    面向对象
    程序 = 对象 + 对象 + 对象 + ...........
    对象 : 被下定义的那个东西就是对象(您看到的,你想到的,有形的,无形的万物皆为对象)
    二、类与对象的概念
    类:大量的拥有相同属性和行为的对象的集合
    对象:根据累的属性和行为而创建的实例化。对象是类的实例化(类是没有空间的)
    注:对象具有唯一性
    举例:
    学生           红孩儿、猪八戒                      类与对象
    水果           苹果、香蕉、栗子                  继承、父子关系、无对象
     
    面向对象的三大特点:封装、继承、多态
    封装:
    继承:
    多态:
    三、构造函数和对象的关系
    a.普通构造函数
    //对象的构造方法
    function Student(newName,oldNem){
    this.name = newName;
    thid.tall = newTall;
    this.eat =function(){
        console.log("在吃饭");
    }
    this.code = function(){
       console.log("在敲代码");
    }
    }
    b.ES6构造方法
    class Birthday{
        constructor(newY,newM,newD){
            this.year = year;
            this.month = month;
            this.day = day;
        }
        showValue(){
             console.log(this.year+","+this.month+","+this.date);
        }
    }
     
    let bir = new Birthday(1989,3,12);
    bir.showValue();
    四、类与类之间的关系
    关联关系:对象和对象之间的连接。在面向对象中,其表现形式为一个类的对象作为另一个类的属性来存在。即has-a
    依赖关系 :一个类的对象作为另一个类的成员对象存在。即use-a
                      指一个类A使用到了另一个类。
    <script>
        class Car{
            constructor(newSpeed) {
                this.speed = newSpeed;
            }
            time(r){
                return Number(r.length/this.speed);
            }
        }
        class Road{
            constructor(newLength) {
                this.length = newLength;
            }
        }
        let c = new Car(60);
        let r = new Road(1000);
     
        console.log(c.time(r));
    </script>
    ----------------------------------------------------------------------
    面向对象的解决问题的思路
    1.找出该问题的有用对象
    2.根据对象抽象出其数据和行为,创建类
    3.各个对象各司其职,执行程序
     
  • 相关阅读:
    《DSP using MATLAB》 示例 Example 9.12
    《DSP using MATLAB》示例 Example 9.11
    《DSP using MATLAB》示例 Example 9.10
    《DSP using MATLAB》示例Example 9.9
    《DSP using MATLAB》示例 Example 9.8
    《DSP using MATLAB》示例Example 9.7
    《DSP using MATLAB》示例 Example 9.6
    《DSP using MATLAB》示例Example 9.5
    《DSP using MATLAB》示例 Example 9.4
    (转载)【C++11新特性】 nullptr关键字
  • 原文地址:https://www.cnblogs.com/yzr-71123/p/11086686.html
Copyright © 2011-2022 走看看