April 2018
Beginner
536 pages
13h 21m
English
The Liskov substitution principle (LSP) states, Subtypes must be substitutable for their base types. Let's look at an example to understand what this means.
We will declare a class named PersistanceService, the responsibility of which is to persist some object into some sort of storage. We will start by declaring the following interface:
interface PersistanceServiceInterface {
save(value: string): string;
}
After declaring the PersistanceServiceInterface interface, we can implement it. We will use cookies as the storage for the application's data:
function getUniqueId() { return Math.random().toString(36).substr(2, 9); } class CookiePersitanceService implements PersistanceServiceInterface { public ...