CS FundamentalsVery hardProduct-company design interview
An object adapter and a class adapter both make class Legacy fit interface Target. Which statement is correct?
- A. An object adapter holds a Legacy instance and delegates to it, so it also works with Legacy's subclasses; a class adapter inherits from Legacy, so it can override Legacy's methods but needs multiple inheritance of implementation
- B. Both use inheritance only
- C. A class adapter wraps an instance while an object adapter inherits
- D. They differ only in name
Correct answer: A. An object adapter holds a Legacy instance and delegates to it, so it also works with Legacy's subclasses; a class adapter inherits from Legacy, so it can override Legacy's methods but needs multiple inheritance of implementation
Composition (object adapter) is more flexible and works in single-inheritance languages like Java; the class adapter binds to one concrete class but can tweak its behaviour by overriding.
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
- Both Facade and Mediator sit between groups of objects. What is the essential difference?
- A Customer may or may not have a discount policy. Instead of writing if policy is not None: total = policy.apply(total) everywhere, the…
- Which form of dependency injection makes required dependencies explicit and allows the object to be immutable and fully initialised as…
- A message broker delivers each message at least once, so consumers sometimes see duplicates (for example after a crash before an ack). A…
- Match the delivery guarantee. P: the consumer acks a message before processing it. Q: the consumer acks only after processing succeeds. R…
- In CQRS, what is separated, and what is a typical consequence?