LLD - Behavioral Design Patterns — Part 2
Identify the error in this Null Object pattern implementation:
class NullCache {
get(key) { return null; }
set(key, value) { /* do nothing */ }
}
function fetchData(cache, key) {
const data = cache.get(key);
if (data) {
return data;
} else {
return 'default';
}
}
const cache = new NullCache();
console.log(fetchData(cache, 'item'));