Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!ux1.cso.uiuc.edu!ux1.cso.uiuc.edu!m.cs.uiuc.edu!p.cs.uiuc.edu!johnson From: johnson@p.cs.uiuc.edu Newsgroups: comp.object Subject: Re: Inheritence and Delegation Message-ID: <135300006@p.cs.uiuc.edu> Date: 13 Oct 89 12:13:00 GMT References: <125984@sun.Eng.Sun.COM> Lines: 43 Nf-ID: #R:sun.Eng.Sun.COM:125984:p.cs.uiuc.edu:135300006:000:2163 Nf-From: p.cs.uiuc.edu!johnson Oct 13 07:13:00 1989 >Delagation is better than Inheritance, because >1) Inheritance violates encapsulation by the superclasses, therefore >2) Inheritance makes concurrency more difficult in the resultant system. I've heard this before. It has never made sense to me, though a later part of the message might clear it up. However, somebody at OOPSLA this year said exactly the opposite--that inheritance was better for concurrency than delegation because delegation introduced performance bottlenecks. I don't really have much of an opinion on the subject yet. >Delagation reflects reality better than inheritance: your car does not >inherit from door, tire, and engine: is is a composite made up of >doors, tires, and an engine. The fact that the window on the left door >is open should have no bearing on the state of other windows or the >fuel injection or tire pressure. Ack! BLechttt! This is evidence of the dread disease of Flavors! This bears NO relationship to real inheritance at all. Inheritance is supposed to be the IS-A relationship, but a Car is not a Door. A door is a component of a car, it is not a superclass of Car. >The average depth of inheritance in most systems is about 3. The >number of object types in many systems is very large, in the dozens to >thousands. Therefore, people tend to favor delagation over inheritance >by a large margin, even when they don't consider it to be an issue. The average depth of inheritance in my systems is more like 5 or 6, but that doesn't change your argument much. However, this argument seems to hinge on the point that components and delegation are the same thing. That is not true. "self" in a delegated message has to be the original reciever. The usual terminology for sending a message to a component in which "self" should be the component is "forwarding". I think that I am in general agreement with the author who sparked this reply. In particular, I believe that component relationship should NOT be modeled by inheritance. Instead, instance variables are a better approach. However, it is important to get terminology right, and not to confuse delegation with forwarding. Ralph Johnson