CS FundamentalsVery hardProduct-company design interview

A drawing app has 4 shape types and must render each through 3 back-ends (SVG, Canvas, PDF). Building one subclass per combination needs 12 classes. Which pattern removes the explosion, and how many concrete classes does it need?

  1. A. Decorator, 7 classes
  2. B. Bridge, 7 classes (4 shapes holding a reference to one of 3 renderers)
  3. C. Abstract Factory, 12 classes
  4. D. Composite, 4 classes

Correct answer: B. Bridge, 7 classes (4 shapes holding a reference to one of 3 renderers)

Bridge separates the shape abstraction from the rendering implementation so the two vary independently: m + n = 4 + 3 = 7 instead of m x n = 12. Composite is about part-whole trees, not two varying dimensions.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic