CS FundamentalsHardProduct-company design interview
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 button with a Dark menu. Which pattern guarantees this best?
- A. Factory Method on each widget class
- B. Singleton
- C. Builder
- D. Abstract Factory, with one concrete factory per theme creating all the related widgets
Correct answer: D. Abstract Factory, with one concrete factory per theme creating all the related widgets
Abstract Factory groups the creation of related products behind one factory per family, so choosing the DarkFactory yields only dark widgets. Factory Method creates one product type at a time and does not enforce family consistency.
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 game renders 1,000,000 trees. Each tree object stores mesh and texture data (about 2 MB, the same for every oak) plus its own x, y…
- An editor must save snapshots of a document's internal state so it can be restored later, without exposing the document's private fields…
- In an air-traffic system, 20 aircraft objects would each need references to all the others to coordinate landings. Routing every message…
- How many of these differences between Proxy and Decorator are correct? 1. Both implement the same interface as the object they wrap. 2. A…
- A class Invoice has methods calculateTotal(), saveToDatabase() and renderPdf(). Which principle does it violate, and what is the usual fix?
- A Worker interface declares work(), eat() and sleep(). RobotWorker implements it and leaves eat() and sleep() throwing 'not supported'…