All quizzesHard
Architectural Patterns
Preview — 3 of 10 questions
What design problem does this factory pattern solve?
javascript
class ReportFactory {
static registeredReports = {};
static register(type, ReportClass) {
this.registeredReports[type] = ReportClass;
}
static create(type) {
const ReportClass = this.registeredReports[type];
if (!ReportClass) {
throw new Error(`Report type '${type}' not registered`);
}
return new ReportClass();
}
}
// Third-party plugin can register new report types
ReportFactory.register("pdf", PDFReport);
ReportFactory.register("excel", ExcelReport);
// Later, third-party code registers new type without modifying factory
ReportFactory.register("custom", CustomReport);
const report = ReportFactory.create("custom");AAllows extending factory with new types without modifying existing code (Open/Closed Principle)
BPrevents new report types from being added
CCreates a singleton factory
DOptimizes report creation performance
In an MVC architecture, which patterns are typically combined?
AObserver, Factory, and Strategy patterns working together
BOnly Singleton pattern
COnly Adapter pattern
DDecorator and Proxy patterns
What problem does the Facade pattern solve when combined with many underlying patterns?
APrevents patterns from conflicting
BPrevents pattern usage altogether
CMakes patterns faster
DSimplifies a complex system with many interacting patterns
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.