Xref: utzoo comp.lang.eiffel:1416 comp.object:2573 Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!apple!motcsd!mcdcup!mcdhup!mcdchg!tellab5!balr!clrcom!rmartin From: rmartin@clear.com (Bob Martin) Newsgroups: comp.lang.eiffel,comp.object Subject: Re: Inheritance and Information Hiding Message-ID: <1991Feb5.143726.17160@clear.com> Date: 5 Feb 91 14:37:26 GMT References: <485@eiffel.UUCP> <488@eiffel.UUCP> <27A86309.281A@tct.uucp> Organization: Clear Communications, Inc. Lines: 45 In article <27A86309.281A@tct.uucp> chip@tct.uucp (Chip Salzenberg) writes: >According to bertrand@eiffel.UUCP (Bertrand Meyer): >>A class POLYGON exists and has a procedure >>``add_vertex'', which it exports. You want >>to add a class RECTANGLE. What do you do? >> >>1. Decide not to use inheritance. >>2. Redo the existing inheritance hierarchy. >>3. Accept that RECTANGLE inherits from POLYGON and does not export >> ``add_vertex''. ... and disallow polymorphic assignments of the form >> p := r where p is of type POLYGON and r of type RECTANGLE. >>4. Accept that RECTANGLE inherits from POLYGON and does not export >> ``add_vertex''. Permit polymorphic assignments of the above form; >> but have the type checker reject as invalid any system which would >> contain both such an assignment and a call p.add_vertex (...), since >> it may lead to a run-time inconsistency. > >In C++, the add_vertex() member function would almost certainly be >virtual; [...] add_vertex becomes a non-problem. The >implementor of RECTANGLE simply provides an appropriate definition of >the RECTANGLE::add_vertex(): a do-nothing function body that returns a >failure indication (if appropriate). > >In the real world, how is this solution deficient? Assume that this example were part of a very large system which added points to POLYGONs all over the place. Assume also that there had never before been a reason for add_point to fail. Your proposed solution _changes_ the interface to class POLYGON since now some POLYGONs (or their derivatives i.e. RECTANGLEs) will issue failure for add_point. Thus it breaks old working code. > >>As an aside (meant to be thought- rather than flame-provoking) >>I have come to realize, although not early enough, that >>information hiding is a greatly overrated goal. This is not a flame, it is a provoked thought. Some people may overrate a goal. That does not devalue the goal. > -- +-Robert C. Martin-----+:RRR:::CCC:M:::::M:| Nobody is responsible for | | rmartin@clear.com |:R::R:C::::M:M:M:M:| my words but me. I want | | uunet!clrcom!rmartin |:RRR::C::::M::M::M:| all the credit, and all | +----------------------+:R::R::CCC:M:::::M:| the blame. So there. |