answersLogoWhite

0

One of the earliest motivations for using inheritance was the re-use of code which already existed in another class. This practice is usually called implementation inheritance.

In most quarters, class inheritance for the sole purpose of code re-use has fallen out of favor.The primary concern is that implementation inheritance does not provide any assurance of polymorphic substitutability-an instance of the re-using class cannot necessarily be substituted for an instance of the inherited class. An alternative technique, delegation, requires more programming effort but avoids the substitutability issue. In C++ private inheritance can be used as form of implementation inheritance without substitutability. Whereas public inheritance represents an "is-a" relationship and delegation represents a "has-a" relationship, private (and protected) inheritance can be thought of as an "is implemented in terms of" relationship.

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake
ProfessorProfessor
I will give you the most educated answer.
Chat with Professor
LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao

Add your answer:

Earn +20 pts
Q: How does inheritance promote code reuse?
Write your answer...
Submit
Still have questions?
magnify glass
imp