Object-oriented polymorphism

Polymorphism: different implementations of the same interface, with the distal end is relatively small

 

The same interface, different performance. js very few applications. It requires a combination of java and other languages ​​interface, rewrite, overloaded functions

 

class People {
    constructor(name) {
        this.name = name
    }
    saySomething() {

    }
}

class A extends People {
    constructor(name) {
        super(name)
    }
    saySomething() {
        alert('I am A')
    }
}

class B extends People {
    constructor(name) {
        super(name)
    }
    saySomething(){
        alert('I am B')
    }
}

let a = new A('a');
a.saySomething();
let b = new B('b');
b.saySomething();

SaySomething example, it defines a method, but subclasses can implement different functions

 

Polymorphic maintaining openness and flexibility subclasses
Oriented programming interface

 

Guess you like

Origin www.cnblogs.com/wzndkj/p/11706687.html