//! 类 类型:类的类型能够通过接口来实现(() => { //? 定义一个接口 interface IFly { //* 该办法没有任何的实现(什么都没有) fly(): any; } //? 定义一个类。这个类的类型上下面定义的接口(实际上,IFly束缚了以后的这个Person的类) class Person implements IFly { //? 实现接口中的办法 fly() { console.log("看看我"); } } //? 实例化对象 const person = new Person(); person.fly(); interface ISwim { swim(): any; } //todo 定义一个类,这个类的类型就是IFly和ISwim(以后这个类能够实现多个接口,一个类能够被多个接口进行束缚) class Person2 implements IFly, ISwim { fly() { console.log("看看我,我是第二个"); } swim() { console.log("看看我 我是第二个"); } } const person2 = new Person2(); person2.fly(); person2.swim(); //! 类能够通过接口的形式,来定义以后这个类的类型 //! 类能够实现一个接口,类也能够实现多个接口,要留神,接口中的内容都要真正的实现 //! 接口能够继承其他人的多个接口 //定义了一个接口,并且继承了下面的接口 interface IWan extends Person2, Person {} //定义一个类,间接实现IFly和ISwim class Person3 implements IWan { fly() { console.log("看看我,我是3个"); } swim() { console.log("看看我 我是第3个"); } } const person3 = new Person3(); person3.fly(); person3.swim(); //! 接口和接口之间叫继承(应用的是extends) //! 类和接口之间叫实现(应用的是implements)})();