Creational Patterns — Series 3

Preview — 3 of 10 questions

Which problem is the Builder pattern aimed at?

AGuaranteeing that only one instance of a class ever exists.
BConstructing an object step by step, so a long list of optional parameters does not turn into a telescoping constructor whose arguments are positional and easy to mix up.
CConverting one interface into another so two incompatible modules can talk.
DNotifying many dependents when one object changes.

What is logged?

javascript
const proto = { greet() { return `hi ${this.name}`; } };

const o = Object.create(proto, {
  name: { value: 'ada', enumerable: true },
  id: { value: 1 },
});

console.log(o.greet(), Object.keys(o).join(','), JSON.stringify(o));
Ahi ada name,id {"name":"ada","id":1}
Bhi undefined {}
Chi ada name,id {"name":"ada"}
Dhi ada name {"name":"ada"}

Which situation calls for an Abstract Factory rather than a plain factory function?

ASeveral related products must be created together and stay consistent — a theme that yields a matching Button, Input and Modal, so a dark button can never end up beside a light modal.
BA single object is expensive to create and should be created only once.
CAn existing class's interface must be adapted to a new one.
DAn algorithm should be selectable at runtime.

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.