February 2019
Beginner
694 pages
18h 4m
English
As we have seen in previous chapters, magic strings are a prime example where we can refactor our code to use an enum resolution. As an example of this, let's consider a ServiceLocator class built around an enum resolution, as follows:
interface ISystemSettings {
}
interface IMailService {
}
enum Interfaces {
ISystemSettings,
IMailService
}
class ServiceLocatorTypes {
public static register(
interfaceName: Interfaces, instance: any) {}
public static resolve(
interfaceName: Interfaces) {}
}
ServiceLocatorTypes.register(Interfaces.ISystemSettings, {});
ServiceLocatorTypes.resolve(Interfaces.ISystemSettings);
Here, we start with two interfaces that we wish to use with our service locator, named ISystemSettings and IMailService ...
Read now
Unlock full access