O'Reilly logo

Mastering TypeScript by Nathan Rozentals

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

A Service Locator

Let's get back to the crux of our problem: given an interface, how do we obtain a concrete implementation of a class that is currently implementing it?

In Chapter 3, Interfaces, Classes and Generics, we wrote a generic class named InterfaceChecker that did a runtime evaluation of a class, to check whether it implemented a specific set of methods and properties. The basic idea behind this InterfaceChecker was that if we provided a metadata class that listed the expected properties and methods of an interface, we could then interrogate a class at runtime against this metadata. If the class had all of the required properties and methods, then it was said to implement the interface.

So, we now have a mechanism—at runtime—to ensure ...

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