Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface BlackAnimal {
- color: string;
- }
- interface AnimalWith4Paws {
- nbPaws: number;
- }
- class Animal implements BlackAnimal, AnimalWith4Paws {
- species: string;
- nbPaws: number;
- color: string;
- constructor(species: string, nbPaws: number, color: string) {
- this.species = species
- this.nbPaws = nbPaws
- this.color = color
- }
- }
- class Cat extends Animal {
- }
- class Dog extends Animal {
- }
- class Bird extends Animal {
- }
- class Fish extends Animal {
- }
- class Insect extends Animal {
- }
- function photographAnimal (all: Animal) {
- console.log("I can shoot this animal : " + all.species)
- }
- function catMiaou (chat: Cat) {
- console.log("I'm a " + chat.species + ", miaou!")
- }
- function dogWoof (chien: Dog) {
- console.log("I'm a " + chien.species + ", woof!")
- }
- function birdFly (bird: Bird) {
- console.log("I'm a " + bird.species + ", I can fly.")
- }
- function fishSwim (fish: Fish) {
- console.log("I'm a " + fish.species + ", I can swim.")
- }
- function animalCaress (paws4: Animal) {
- if (paws4.nbPaws === 4) {
- console.log("Youpi, I'm a " + paws4.species + " with " + paws4.nbPaws + " paws, caress me!")
- } else {
- console.log("Shit, no caress for me, I'm a " + paws4.species + " with " + paws4.nbPaws + " paws.")
- }
- }
- function feedBlackAnimal (feed: Animal) {
- if (feed.color === "black") {
- console.log("Youpi, I can feed this animal because it's " + feed.color)
- } else {
- console.log("Shit, I can't feed this animal because it's " + feed.color)
- }
- }
- let europeanCat = new Animal("cat", 4, "black");
- let chartreuxCat = new Animal("cat", 4, "white")
- let terreNeuveDog = new Animal("dog", 4, "black")
- let moonDog = new Animal("dog", 4, "brown")
- let mesange = new Bird("bird", 0, "gray")
- let merle = new Bird("bird", 0, "black")
- let thon = new Fish("fish", 0, "")
- let requin = new Fish("fish", 0, "")
- let asticot = new Insect("insect", 0, "")
- photographAnimal(europeanCat)
- catMiaou(europeanCat)
- dogWoof(terreNeuveDog)
- birdFly(mesange)
- fishSwim(thon)
- feedBlackAnimal(europeanCat)
- feedBlackAnimal(chartreuxCat)
- feedBlackAnimal(terreNeuveDog)
- feedBlackAnimal(moonDog)
- feedBlackAnimal(merle)
- animalCaress(europeanCat)
- animalCaress(terreNeuveDog)
- animalCaress(requin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement