diff --git a/Md03_Dev_Back_end/Bloco26/26.2/conteudo001.ts b/Md03_Dev_Back_end/Bloco26/26.2/conteudo001.ts new file mode 100644 index 00000000..a926f95e --- /dev/null +++ b/Md03_Dev_Back_end/Bloco26/26.2/conteudo001.ts @@ -0,0 +1,70 @@ +class Animal { + constructor(public name: string, private _birthDate: Date) {} + + get age() { + const timeDiff = Math.abs( + Date.now() - + new Date(this._birthDate).getTime() + ); + + return Math.floor(timeDiff / (1000 * 3600 * 24) / 365.25); + } +} + +class Mammal extends Animal { + walk() { + console.log(`${this.name} está andando`); + } +} + +class Bird extends Animal { + fly() { + console.log(`${this.name} está voando!`) + } +} + +const tigger = new Mammal('tigre', new Date(Date.parse('May 03, 2020'))); +const parrot = new Bird('Papagaio', new Date(Date.parse('Jun 07, 2017'))); + +const main = (animal: Animal) => { + console.log(animal.age); +} + +main(tigger); +tigger.walk(); +console.log(parrot.age); +parrot.fly(); + +class Superclass { + constructor(public isSuper: boolean = true) {} + + protected sayHello() { + console.log('Olá Mundo!'); + } +} + +class Subclass extends Superclass { + constructor() { + super(false); + } + + sayHello2() { + this.sayHello(); + } +} + +function myFunction(objClass: Subclass) { + objClass.sayHello2(); +} + +function mySuperFunction(objClass: Superclass) { + (objClass.isSuper) ? console.log('super') : console.log('sub'); +} + +const objSubClass = new Subclass(); +const objSupreClass = new Superclass(); + +myFunction(objSubClass); +// myFunction(objSupreClass); +mySuperFunction(objSubClass); +mySuperFunction(objSupreClass); \ No newline at end of file diff --git a/Md03_Dev_Back_end/Bloco26/26.2/conteudoPt2.ts b/Md03_Dev_Back_end/Bloco26/26.2/conteudoPt2.ts new file mode 100644 index 00000000..2e105fbf --- /dev/null +++ b/Md03_Dev_Back_end/Bloco26/26.2/conteudoPt2.ts @@ -0,0 +1,29 @@ +interface Animal { + name: string; + age: number; + + getBirthDate(): Date; +} + +class Birds implements Animal { + constructor(public name: string, private birthDate: Date) {} + + get age() { + var timeDiff = Math.abs(Date.now() - new Date(this.birthDate).getTime()); + + return Math.floor(timeDiff / (1000 * 3600 * 24) / 365.25); + } + + getBirthDate(): Date { + return this.birthDate; + } + + fly() { + console.log(`${this.name} está voando!`); + } +} + +export const parrot = new Birds('Papagaio',new Date(Date.parse('Aug 16, 2015'))); + +console.log(parrot.age); +parrot.fly(); \ No newline at end of file diff --git a/Md03_Dev_Back_end/Bloco26/26.2/fixarConteudo.ts b/Md03_Dev_Back_end/Bloco26/26.2/fixarConteudo.ts new file mode 100644 index 00000000..c6898c0e --- /dev/null +++ b/Md03_Dev_Back_end/Bloco26/26.2/fixarConteudo.ts @@ -0,0 +1,17 @@ +interface MyInterface { + myNumber: number; + + myFunc(myParam: number): string; +} + +class MyClass implements MyInterface { + constructor(public myNumber: number) {} + + myFunc(num: number) { + return `${num + this.myNumber}`; + } +} + +const numero = new MyClass(3); + +console.log(numero.myFunc(2)); \ No newline at end of file