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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1116ece181be1aea X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-14 12:53:13 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wn14feed!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi_feed4!attbi.com!rwcrnsc52.ops.asp.att.net.POSTED!not-for-mail Message-ID: <3F64C712.9010105@attbi.com> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Is the Writing on the Wall for Ada? References: <3F615341.4000100@attbi.com> <568ede3c.0309121211.743a8da2@posting.google.com> <3F634E58.4080803@attbi.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.34.139.183 X-Complaints-To: abuse@comcast.net X-Trace: rwcrnsc52.ops.asp.att.net 1063569192 24.34.139.183 (Sun, 14 Sep 2003 19:53:12 GMT) NNTP-Posting-Date: Sun, 14 Sep 2003 19:53:12 GMT Organization: Comcast Online Date: Sun, 14 Sep 2003 19:53:12 GMT Xref: archiver1.google.com comp.lang.ada:42487 Date: 2003-09-14T19:53:12+00:00 List-Id: Hyman Rosen wrote: > Robert I. Eachus wrote: > >> You inherit from two virtual classes, then use concrete mix-ins to >> implement the classes. > > > I still feel like we're talking past each other. I am showing you why > one might want to inherit from two different concrete classes. In my > example, you want an object which is Colorable and Resizable, and you > want to reuse the concrete implementations of the adapter classes. There is no problem inheriting from two concrete classes. I showed how it is done in Ada. What I have been saying is that you can't have direct inheritance (with the isa relationship) from two unrelated classes. This paper by Bertrand Meyer: http://archive.eiffel.com/doc/manuals/technology/bmarticles/joop/multiple.html has a humorous example of the problem. It is wrong to create a class Apple Pie by inheriting from Apple and Pie. An apple pie isa pie, but it isn't an apple. The article by Bertrand Meyer describes what is going on in terms of subtyping and extension. But let's go back to the apple pie example. An apple isa pie, but a pie is not necessarily an apple pie. In other words, apple pies are a proper subset of pies. What about the situation where you only want to extend a class, but not subset it. That is direct inheritance. Let's say I want to extend the class integer by adding a routine which will convert the integer to an English character string: function English_Name(I: Integer) return String; So English_Name(123) will return "one hundred and fortythree". Now lets add an operations that returns the German Name, so German_Name(143) will return "einhundert drei und vierzig". So far so good. But let's say I don't want to name the language. In Ada I can say: package English is type Number is new Integer; function Name return String; end English; And do the same for French, German, Italian, and so on. Now English.Number isa Integer, and the relationship is transitive. An Integer isa English.Number, but without the extension provided by the name function. That is direct inheritance. Notice that due to the transitive nature of the isa relationship, an English.Number isa Integer and an Integer isa German.Number, therefore an English.Number isa German.Number. Mix-ins in Ada typically provide this type of direct inheritance. In Ada derived types can do subtyping: type Small_Numer is Integer range -256..255; As can subtypes: subtype Small_Integer is Integer range -256..255; So in Ada it is typical to split subtyping and type extension. Now what is wrong with multiple direct inheritance? It is either wrong, or useless. If you want to inherit from two classes that are identical, why bother? If you want to directly inherit from two classes that are different, the new subclass can't force the two parent classes to be identical. But the child class has to be identical to both parents (in terms of state, not operations). Can't be done. If you use mix-in style inheritance, the new class is a subclass (perhaps a non-proper subclass) of the parent with added state. No problem. There is an isa relationship from the new class to its parent, but not from parent to child. An apple pie isa pie, but a pie may or may not be an apple pie. > Are you saying that this example is somehow invalid? You can't do it > in Ada, so you have to use the mixin style if you want something like > this, but that's just a deficiency of Ada. There are several types of inheritance. Direct inheritance copies the state. Interface inheritance does not copy the state, but provides added operations. Mix-in inheritance augments the state. In the normal notation for these things, your example took a type with state = color, and a type with state = size and created a type with state = color x size. So that is what my example did as well. The reason for the product notation is that the number of possible states for the final type is the product of all the valid color states and all the valid size states. It is impossible in Ada--or any other language--to create a new type with the number of possible states equal to the number of possible colors and also equal to the number of possible sizes. (Assuming those numbers are different.) > You can use the mixin style in C++ too, of course, but if you have > constructors the mixin style forces you to pass the constructor > parameters around somewhat inconveniently; it's easier to do the > direct multiple inheritance. Notice that your mixin example didn't > have the initializing parameters that my C++ example did. AFAIK, I copied that exactly. The initial color was = 0, and the initial size was = 1.0. I did not copy the destructors because they weren't required in Ada. -- Robert I. Eachus "As far as I'm concerned, war always means failure." -- Jacques Chirac, President of France "As far as France is concerned, you're right." -- Rush Limbaugh