CS FundamentalsHardCognizant · Capgemini pattern
A stock-price service must notify every registered display widget whenever the price changes, without knowing the widgets' concrete classes. Which pattern fits?
- A. Adapter
- B. Observer
- C. Builder
- D. Singleton
Correct answer: B. Observer
Observer defines a one-to-many dependency: the subject keeps a list of subscribers and calls their update method on each change, staying decoupled from their concrete types.
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
- Your application expects a PaymentGateway interface, but the third-party library you must use exposes a different API. Which pattern lets…
- class Square extends Rectangle overrides setWidth() so that it also changes the height. Code that sets width = 5 and height = 4 on a…
- A ReportService creates a new MySqlDatabase() directly inside its constructor. Refactoring it to receive a Database interface through its…
- Which HTTP method is NOT idempotent by definition?
- A logged-in user with a valid token calls an admin-only API endpoint. Which status code should the server return?
- In the IaaS model (for example a plain cloud virtual machine), which of these is the customer's responsibility rather than the provider's?