Skip to content

Instantly share code, notes, and snippets.

interface Walker {
walk(): void;
}
interface Swimmer {
swim(): void;
}
interface Flyer {
fly(): void;
interface Animal {
fly(): void;
walk(): void;
swim(): void;
}
class Dog implements Animal {
public fly(): void {
// a dog can't fly
class Player {
public kickBallWithFeet(): void {
console.log("Kicking the ball with feet!")
}
}
class HandsUsingPlayer extends Player {
public holdBallWithHands(): void {
console.log("Holding the ball with hands!")
class Player {
public kickBallWithFeet(): void {
console.log("Kicking the ball with feet!")
}
public holdBallWithHands(): void {
console.log("Holding the ball with hands!")
}
}
interface Player {
calculateGameRating(): number;
}
class Midfielder implements Player {
public assists: number;
public goals: number;
constructor(assists: number, goals: number) {
class Midfielder {
public assists: number;
public goals: number;
constructor(assists: number, goals: number) {
this.assists = assists;
this.goals = goals;
}
}
class Patient {
public firstName: string;
public lastName: string;
public email: string;
public age: number;
}
class ReportGenerator {
public saveToPdf(patient: Patient): void {
// here is code to generate PDF report for patient
class Patient {
public firstName: string;
public lastName: string;
public email: string;
public age: number;
public savePatientReport(): void {
// here is code to generate PDF report for patient
}
}
interface IOcassion {
accept(singer: ISinger): void;
}
interface ISinger {
singChildrenSongs(ocassion: ChildBirthday): void;
singWeddingSongs(ocassion: Wedding): void;
singConcertSongs(ocassion: Concert): void;
}
const applePie: ApplePie = new ApplePie();
const pumpkinPie: PumpkinPie = new PumpkinPie();
applePie.makeDough();
applePie.addPieIngredient();
applePie.bake();
pumpkinPie.makeDough();
pumpkinPie.addPieIngredient();
pumpkinPie.bake();