Applying the SOLID principles

As we have previously mentioned, interfaces are fundamental features when it comes to following the SOLID principles, and we have already put the first two SOLID principles into practice.

We have already discussed the single responsibility principle. Now, we will see real examples of the three remaining principles.

The Liskov substitution principle

The Liskov substitution principle (LSP) states, Subtypes must be substitutable for their base types. Let's take a 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 ...

Get TypeScript: Modern JavaScript Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.