From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fac41,9a0ff0bffdf63657 X-Google-Attributes: gidfac41,public X-Google-Thread: 1108a1,9a0ff0bffdf63657 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public X-Google-Thread: f43e6,9a0ff0bffdf63657 X-Google-Attributes: gidf43e6,public From: Loryn Jenkins Subject: Re: Which wastes more time? (Was Re: Software landmines (loops)) Date: 1998/09/06 Message-ID: <35F1C0B9.8A50CEB0@s054.aone.net.au>#1/1 X-Deja-AN: 388263384 Content-Transfer-Encoding: 7bit References: <6rfra4$rul$1@nnrp1.dejanews.com> <35DBDD24.D003404D@calfp.co.uk> <6sbuod$fra$1@hirame.wwa.com> <6sebjr$b69$1@nnrp1.dejanews.com> <6sff74$q0s@gurney.reilly.home> <6sh2j5$jnl$1@nnrp1.dejanews.com> <35EC2E5A.16DB6CB1@bigfoot-.com> <6sjc0a$1lk$3@news.indigo.ie> <35EFB09E.15412933@s054.aone.net.au> <35f2bd98.40599408@news.erols.com> <35F06A58.F968BDE1@s054.aone.net.au> <35f48276.90997557@news.erols.com> <35F0C3C9.D1E56FF3@s054.aone.net.au> <6srh67$sj5$1@hirame.wwa.com> X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii X-Trace: news.mel.aone.net.au 905036055 5664 203.102.238.34 (5 Sep 1998 22:54:15 GMT) Organization: TekRite Pty Ltd Mime-Version: 1.0 Reply-To: loryn@acm.org NNTP-Posting-Date: 5 Sep 1998 22:54:15 GMT Newsgroups: comp.lang.eiffel,comp.object,comp.software-eng,comp.lang.ada Date: 1998-09-05T22:54:15+00:00 List-Id: > >The second (counter) example is inspired by OOSCII, Chapter 12. In it, > >if I recall correctly, Bertrand has class CAR_OWNER inherit from class > >PERSON. (He offers this as an example of 'how to do inheritance well'.) > >He implies that this is acceptable modelling for an application. Now, > >while I can imagine this working for some applications, I can't believe > >it is acceptable. > > > >I can't believe it is acceptable because it does not model our concept > >of reality. Instead, it should have been modelled as a role of a person. > >That is CAR_OWNER inherits from PERSON_ROLE, and PERSON_ROLE has an > >attribute of type PERSON. > > > >Modelling it this way would have future-proofed the application against > >handling situations when people in the application became car owners and > >then stopped being car owners. Even if it was valid for an application, > >the second is preferable, because I don't have to scratch my head, > >wondering about the possible implications. > > I found the example in Chapter 24. Sorry, it is in Chapter 24. > Meyer is complaining about Ian > Somerfield's description of multiple inheritance in his "Software > Engineering" textbook. (side note: I find these unkind attacks by Meyer all > too frequent. He could have just said: "I disagree with Somerfield" and > left it at that.) In any case Somerfields model had CAR_OWNER multiply > inheriting from CAR and PERSON. Certainly, in light of what we know today, > this would not be an acceptable model. I think classification theory has been around for an awful long time (didn't Plato initiate study into this field?); surely you can't excuse the Ian Somerfield because he wrote a mere few years ago. (I think) Meyer is quite correct in pointing this out to be a ridiculous model. It certainly isn't a good example. > Meyer presents a model in which > CAR_OWNER inherits from PERSON and uses CAR. And this is certainly a much > better model. Agreed. But it still flouts basic classification theory. I find this test to be a very useful in finding whether a (sub-type) inheritance relationship should hold: Is the child class a type of the parent class, and will it be for the whole of its existence? And, is the parent class a supertype of the child class, and will it be for the whole of its existence? That is, in this example: (1) Is a CAR_OWNER a PERSON, and will it be for the whole of its existence? (A1) Yes. (2) Is a PERSON a CAR_OWNER, and will it be for the whole of its existence? (A2) No. Any PERSON can buy and sell cars, moving its status from car owner to not multiple times during their life. As far as I'm concerned, this flouts basic classification theory. As far as I'm concerned, this is *wrong*. (How can you claim to be programming for reuse, as Meyer so eloquently points out as a fundamental goal, and model things so rigidly? So incorrectly?) However, I can easily understand why Bertrand modelled things like so: simplicity. He was simply trying to make a point about the difference between inheritance and clientship. In hindsight, I think he may have been better off choosing a simple example that works well in all contexts. > However, I strongly sympathize with motivation. I agree that we should give > thought to 'future proofing' our application structures (although I don't > think that a simple reliance on real world structure actually accomplishes > that goal). The Role Pattern (very similar to Gamma et al's State Pattern) just described here doesn't necessarily model 'the real world'. I think it does model our 'concept of the world', according to a certain classification theory. Loryn Jenkins