Path: utzoo!attcan!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.object Subject: Re: testing object oriented programs Message-ID: <54873@microsoft.UUCP> Date: 25 May 90 18:34:14 GMT References: <1990May20.154035.15064@axion.bt.co.uk> <54783@microsoft.UUCP> <1990May23.061147.22444@tukki.jyu.fi> <1990May23.171152.29448@Neon.Stanford.EDU> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 43 In article <1990May23.171152.29448@Neon.Stanford.EDU> pallas@Neon.Stanford.EDU (Joe Pallas) writes: >Inheritance does NOT weaken encapsulation. You cannot "break" a class >by inheriting an implementation from it. You can, however, create a >broken class by inheriting an implementation from an unbroken class. >The correctness of an implementation says nothing about the >correctness of implementations which inherit from it. I'd claim in the following trivial example, the base class *is* broken -- but you cannot tell that by testing the base class without deriving from it. Conversely, the derived class *is not* broken -- but the bug in the base class only shows up when testing the derived class. So I claim that inheritence *does* weaken encapsulation, and you *can* break a class by inheriting an implementation from it -- if the base class is never derived from, then the present implementation of the base class is just fine! Only in the presence of derivation need the base class be fixed. class BASE { public: virtual void PrintClassName() { printf("BASECLASS\n"); } virtual void PrintBaseClassName() { PrintClassName(); } }; class DERIVED : public BASE { public: void PrintClassName() { printf("DERIVEDCLASS\n"); } }; main() { BASE* pbase; pbase = new BASE; pbase->PrintClassName(); pbase->PrintBaseClassName(); pbase = new DERIVED; pbase->PrintClassName(); pbase->PrintBaseClassName(); }