TITLE: LSP, inheritance, and aggregation (Newsgroups: comp.lang.c++.moderated, 23 Jan 98) KAPETANAKIS: G.Kapetanakis-CSSE95@cs.bham.ac.uk says... > Is it possible to do inheritance and only inherit some (not all) public: > member functions? > > This may sound stupid, but if a base class has many public: members and > a derived class would only need a few of them, then it would be more > efficient for the derived class to inherit selectively from the base > class. COFFIN: jcoffin@taeus.com (Jerry Coffin) The class can use private or protected inheritance from the base class, then include public front-ends for the inherited functions it wants to make public. Whether I'd _recommend_ doing this is a different question: it might make sense at times, but keep the Liskov substitution principle in mind: derivation normally implies that objects of the derived class can be substituted for objects of the base class under any circumstances. If some operations of the base class don't make sense for the derived class, you may not want to use inheritance at all. The Liskov substitution principle certainly applies to public inheritance but doesn't really in the case of private inheritance. Rather than expressing an "is-a" relationship, private inheritance is usually said to express a "uses for implementation" relationship to the base class. However, in a case like this, unless the two really do bear quite a close relationship, it may be better to simply embed an object of the proposed base class IN the proposed derived class instead of using inheritance at all.