July 2017
Intermediate to advanced
300 pages
5h 43m
English
Similar to what you might be used to in other languages, in TypeScript, we can use abstract classes and methods. The abstract class is meant only for extending. One cannot create instances of the abstract class. Methods defined as abstract are required for implementation in any subclasses:
abstract class Starship {
constructor( protected speed: number = 0 ) {
}
abstract speedUp( increment: number ): void;
}
class LightFreighter extends Starship {
public speedUp( increment: number ): void {
this.speed = this.speed + increment;
}
}
Abstract classes are quite similar to interfaces, except a class can implement multiple interfaces, but extend only one abstract class.
Read now
Unlock full access