Abstract Class Methods
Learn about abstract class methods, their definition and implementation in derived classes, and practical applications.
We'll cover the following...
Abstract class methods in TypeScript
An abstract class method is similar to an abstract class in that it is designed to be overridden. In other words, declaring a class method as abstract means that a derived class must provide an implementation of this method. For this reason, abstract class methods are not allowed to provide a function implementation.
As an example of this, let’s update the EmployeeBase
class:
// Define an abstract class EmployeeBase with the following properties and methods:// - `id` property of type number// - `name` property of type string// - `doWork` method with no return type (abstract method)// - constructor that initializes `id` and `name` properties with `id` and `name` argumentsabstract class EmployeeBase {public id: number;public name: string;// Abstract method with no implementation, to be overridden by derived classesabstract doWork(): void;constructor(id: number, name: string) {this.id = id;this.name = name;}}
Abstract class defining methods and properties
Here, we have added a class method named ...