2.9 of 5 26 reviews Denver, CO 50 to 149 Employees

MapQuest Senior Software Engineer Interview Question

I interviewed in Denver, CO and was asked:
"Explain the reasoning behind the OO practice of favoring composition over inheritance. When would you use one or the other?"
Tags: design, software, object oriented
Add Tags [?]
Answer Flag Question

Part of a Senior Software Engineer Interview Review - one of 6 MapQuest Interview Reviews

Answers & Comments

of 0
Composition means that an object's behaviors are specified by other objects it contains. For instance, a Dragon class might contain a Movement object that specifies flight. Inheritance, as is usually used in OO, means that behavior is specified by an object's position in a class heirarchy. A Dragon would inherit from a FlyingObject class, for instance, and flight behavior would be coded there.

Inheritance makes refactoring behavior tricky, because changing a behavior (e.g. a dragon that can fly in SPACE) implies changing that behavior for all objects that inherit from a superclass. With a design based on composition, the space dragon is as simple as creating a new Movement object that details how to move through space.
- Interview Candidate on Sep 14, 2012 Flag Response

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.

Glassdoor is your free inside look at MapQuest interview questions and advice. All interview reviews posted anonymously by MapQuest employees and interview candidates.