Look Up Plugins by Name, Fully Typed
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Write a class PluginRegistry<Plugins>, where Plugins maps each plugin name to that plugin's type. register(name, plugin) stores a plugin (replacing any earlier one of that name) and returns the registry, so calls can be chained; get(name) returns the plugin and throws if none is registered under that name; has(name) says whether one is. Type it so get("markdown") returns exactly the markdown plugin's type, unknown names are rejected, and registering a plugin of the wrong shape is a type error.
Your code must pass
- Returns a registered plugin
- Throws for a plugin that isn't registered
- register can be chained and replaces a plugin
- Has no type errors
- get returns that plugin's type
- Rejects an unknown name
- Rejects a plugin of the wrong shape