EasyTypeScript

Adapter

TypeScriptDesign PatternsStructuralAdapter

Make an existing class's incompatible interface work with the interface client code expects, without modifying the original class.

OldLogger only has logMessage(msg) returning 'OLD:' + msg. The rest of the app expects a Logger with info(msg) returning 'INFO:' + msg.

Implement `LoggerAdapter`, wrapping an OldLogger to satisfy the Logger interface.

solve(messages) logs each message through the adapter and returns the results.

Sample tests

Test #1Single message
Input: [["hi"]]
Output: ["INFO:hi"]
Test #2Multiple messages
Input: [["a","b"]]
Output: ["INFO:a","INFO:b"]
Test #3No messages
Input: [[]]
Output: []