129. Composition

Question.2

Two developers model a GPS module that uses UART:

Developer A -- Inheritance:

class GPS : public UART { /* GPS is-a UART? */ };

Developer B -- Composition:

class GPS {
   UART& uart;  // GPS has-a UART
public:
   GPS(UART& u) : uart(u) {}
};

Which is better embedded C++ practice?

Need Help? Refer to the Quick Guide below

Select Answer