November 2019
Beginner
804 pages
20h 1m
English
In terms of OO design, we have seen that interfaces play a big role as they allow us to define and enforce contracts in a code base, whether for internal or external (that is, client) code.
First of all, of course, TypeScript interfaces allow you to define such contracts. Here's a simple example:
interface MusicPlayer {
play(): void;
pause(): void;
stop(): void;
rewind(seconds: number): void;
fastForward(seconds: number): void;
}
As you can see, we just need to use the interface keyword and list the method signatures. Any element realizing (that is, implementing) this interface will have to implement those methods.
Here's how a class could implement the interface of the previous example:
class BasicMusicPlayer implements ...
Read now
Unlock full access