Skip to content

Instantly share code, notes, and snippets.

@nutchy
Last active January 3, 2021 11:27
Show Gist options
  • Save nutchy/447c48cecb82513aa3f6d42fb1399522 to your computer and use it in GitHub Desktop.
Save nutchy/447c48cecb82513aa3f6d42fb1399522 to your computer and use it in GitHub Desktop.
interface Shape {
getArea: () => number
}
class Circle implements Shape {
constructor(private radius: number = 0) {}
getArea() {
return Math.PI * this.radius * this.radius
}
}
class Rectangle implements Shape {
constructor(private width: number = 0, private height: number = 0) {}
getArea() {
return this.width * this.height
}
}
function printArea(s: Shape) {
console.log(s.getArea())
}
printArea(new Circle(2))
printArea(new Rectangle(2,3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment