Last active
January 3, 2021 11:27
-
-
Save nutchy/447c48cecb82513aa3f6d42fb1399522 to your computer and use it in GitHub Desktop.
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 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