Created
September 26, 2018 20:34
-
-
Save JeromeBATAILLE/94c4dd98646893a5527549d08caece7e to your computer and use it in GitHub Desktop.
Typescript POO et Classes!
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
interface Photographiable { | |
photographier(); | |
} | |
interface Caressable { | |
caresser(); | |
} | |
interface Nourrissable { | |
nourrir(); | |
} | |
interface Aboyer { | |
aboyer(); | |
} | |
interface Miauler { | |
miauler(); | |
} | |
interface Voler { | |
voler(); | |
} | |
interface Nager { | |
nager(); | |
} | |
class Animal implements Caressable, Photographiable, Nourrissable, Aboyer, Miauler, Voler, Nager { | |
type : string; | |
race : string; | |
nbPattes: number; | |
isNoir: boolean; | |
constructor(type :string, race : string, nbPattes : number, isNoir : boolean) { | |
this.type = type; | |
this.race = race; | |
this.nbPattes = nbPattes; | |
this.isNoir = isNoir; | |
} | |
photographier(){ | |
if (this.type == "Animal") { | |
console.log("Photo ! Cheeeeeeese !"); | |
} | |
} | |
caresser(){ | |
if (this.nbPattes === 4) { | |
console.log("Caresser"); | |
} | |
} | |
nourrir(){ | |
if (this.isNoir == true) { | |
console.log("Miam miam !"); | |
} | |
} | |
aboyer(){ | |
if (this.race == "Chien"){ | |
console.log("Ouaf ouaf !"); | |
} | |
} | |
miauler(){ | |
if (this.race == "Chat") { | |
console.log("Miaoooouuu !"); | |
} | |
} | |
voler(){ | |
if (this.race =="Oiseau"){ | |
console.log("Flap flap !"); | |
} | |
} | |
nager(){ | |
if (this.race =="Poisson"){ | |
console.log("Splash splash !"); | |
} | |
} | |
} | |
class ChienMoonMoon extends Animal { | |
} | |
class ChienTerreNeuve extends Animal { | |
} | |
class ChatEuropeen extends Animal { | |
} | |
class ChatChartreux extends Animal { | |
} | |
class Mesange extends Animal { | |
} | |
class Merle extends Animal { | |
} | |
class Thon extends Animal { | |
} | |
class Requin extends Animal { | |
} | |
class Asticot extends Animal { | |
} | |
/* ---------------------------------------------TESTS--------------------------------------*/ | |
const chat1 = new ChatEuropeen("Animal", "Chat", 4, true); | |
console.log("---Chat Européen---"); | |
chat1.photographier(); | |
chat1.caresser(); | |
chat1.nourrir(); | |
chat1.aboyer(); | |
chat1.miauler(); | |
chat1.voler(); | |
chat1.nager(); | |
console.log(""); | |
const chat2 = new ChatChartreux("Animal", "Chat", 4, false); | |
console.log("---Chat Chartreux---"); | |
chat2.photographier(); | |
chat2.caresser(); | |
chat2.nourrir(); | |
chat2.aboyer(); | |
chat2.miauler(); | |
chat2.voler(); | |
chat2.nager(); | |
console.log(""); | |
const chien1 = new ChienTerreNeuve("Animal", "Chien", 4, true); | |
console.log("---Chien Terre-Neuve---"); | |
chien1.photographier(); | |
chien1.caresser(); | |
chien1.nourrir(); | |
chien1.aboyer(); | |
chien1.miauler(); | |
chien1.voler(); | |
chien1.nager(); | |
console.log(""); | |
const chien2 = new ChienMoonMoon("Animal", "Chien", 4, false); | |
console.log("---Chien MoonMoon---"); | |
chien2.photographier(); | |
chien2.caresser(); | |
chien2.nourrir(); | |
chien2.aboyer(); | |
chien2.miauler(); | |
chien2.voler(); | |
chien2.nager(); | |
console.log(""); | |
const oiseau1 = new Mesange("Animal", "Oiseau", 2, false); | |
console.log("---Mésange---"); | |
oiseau1.photographier(); | |
oiseau1.caresser(); | |
oiseau1.nourrir(); | |
oiseau1.aboyer(); | |
oiseau1.miauler(); | |
oiseau1.voler(); | |
oiseau1.nager(); | |
console.log(""); | |
const oiseau2 = new Mesange("Animal", "Oiseau", 2, true); | |
console.log("---Merle---"); | |
oiseau2.photographier(); | |
oiseau2.caresser(); | |
oiseau2.nourrir(); | |
oiseau2.aboyer(); | |
oiseau2.miauler(); | |
oiseau2.voler(); | |
oiseau2.nager(); | |
console.log(""); | |
const poisson1 = new Thon("Animal", "Poisson", 0, false); | |
console.log("---Thon---"); | |
poisson1.photographier(); | |
poisson1.caresser(); | |
poisson1.nourrir(); | |
poisson1.aboyer(); | |
poisson1.miauler(); | |
poisson1.voler(); | |
poisson1.nager(); | |
console.log(""); | |
const poisson2 = new Requin("Animal", "Poisson", 0, false); | |
console.log("---Requin---"); | |
poisson2.photographier(); | |
poisson2.caresser(); | |
poisson2.nourrir(); | |
poisson2.aboyer(); | |
poisson2.miauler(); | |
poisson2.voler(); | |
poisson2.nager(); | |
console.log(""); | |
const asticot = new Asticot("Animal", "Asticot", 0, false); | |
console.log("---Asticot---"); | |
asticot.photographier(); | |
asticot.caresser(); | |
asticot.nourrir(); | |
asticot.aboyer(); | |
asticot.miauler(); | |
asticot.voler(); | |
asticot.nager(); | |
console.log(""); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment