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?
- A. Decorator, 7 classes
- B. Bridge, 7 classes (4 shapes holding a reference to one of 3 renderers)
- C. Abstract Factory, 12 classes
- 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.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- A compiler has a stable set of AST node classes (Number, BinaryOp, Call, Variable) but keeps adding new operations: type-check…
- A file-manager must compute the total size of a folder, where a folder may contain files and other folders, and client code should call…
- A text editor needs multi-level undo and redo, and also wants to queue and log user actions such as 'insert text' or 'delete line'. Which…
- A vending machine's behaviour for insertCoin() and selectItem() differs completely in the states Idle, HasCoin, Dispensing and SoldOut…
- A report class defines generate() as: fetchData(); format(); export(). Subclasses PdfReport and CsvReport override only format() and…
- An app must create a consistent family of UI widgets (Button, Checkbox, Menu) for either a Light or a Dark theme, never mixing a Light…