O'Reilly logo

Cross-platform Desktop Application Development: Electron, Node, NW.js, and React by Dmitry Sheiko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Abstract classes

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required