Created
July 7, 2019 15:47
-
-
Save tecnocrata/d34cacee27cb4295f78ed47e251a9239 to your computer and use it in GitHub Desktop.
Typescript entendiendo Shapes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Shapes no esta directamente relacionado a la herencia | |
| interface Mamifero{ | |
| cantidad:number | |
| } | |
| interface Comedor{ | |
| comida:string, | |
| comer():number | |
| } | |
| class Animal implements Mamifero, Comedor{ | |
| comer(): number { | |
| thrownewError("Method not implemented."); | |
| } | |
| cantidad: number; | |
| comida: string; | |
| } | |
| class Perro { | |
| cantidad:number | |
| comida: string; | |
| // comer(): number { | |
| // throw new Error("Method not implemented."); | |
| // } | |
| } | |
| let x = new Animal(); | |
| let y = new Perro(); | |
| x =y; //Error si NO descomentan el metodo comer, es decir si la clase perro no implementa comer | |
| y = x;//Esta asignacion es posible incluso aunque ambos objetos sean instanciados de clases diferentes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment