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 14:44:10 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!newsread1.news.atl.earthlink.net.POSTED!not-for-mail Sender: mheaney@MHEANEYX200 Newsgroups: comp.lang.ada Subject: Re: Is the Writing on the Wall for Ada? References: From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 14 Sep 2003 21:44:09 GMT NNTP-Posting-Host: 65.110.133.134 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.atl.earthlink.net 1063575849 65.110.133.134 (Sun, 14 Sep 2003 14:44:09 PDT) NNTP-Posting-Date: Sun, 14 Sep 2003 14:44:09 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:42497 Date: 2003-09-14T21:44:09+00:00 List-Id: olehjalmar kristensen - Sun Microsystems - Trondheim Norway writes: > Beats me. In fact, one of the *nice* things about the C++ multiple > inheritance is that it allows me to express roles (a la Reenskaug) and > then combine different roles in the same object without jumping > through hoops. In Smalltalk you need an extra tool to do this, in C++ > all you need is a little care. I suppose it *could* be done in Ada > with generics, but I have not tried it, and it would certainly be more > obfuscated. The mechanism for implementing roles (what we call "views") in Ada95 is access discriminants, not MI. For example, if I want to have a "persistence role," I can do this: package Persistence_Views is type Root_Persistence_Type is abstract tagged limited null record; type Persistence_Class_Access is access all Root_Persistence_Type'Class; procedure Write (Stream : in out Root_Stream_Type'Class; Persistence : access Root_Persistence_Type) is abstract; procedure Read (Stream : in out Root_Stream_Type'Class; Persistence : access Root_Persistence_Type) is abstract; procedure Save (Persistence : access Root_Persistence_Type'Class); end Persistence_Views; To add support for persistence to a type, you can do this: with Persistence_Views; package P is type T is tagged limited private; function Persistence (O : access T) return Persistence_Class_Access; ... private type Persisence_Type (O : access T) is new Root_Persistence_Type with null record; procedure Write (...); procedure Read (...); type T is tagged limited record Persistence : aliased Persistence_Type (T'Access); ... end record; end P; So now given an object of type T (which supports persistence), you can oo this: procedure Op (O : in out T) is begin Save (Persistence (O'Access)); end; We've shown one role here, but in fact any number of views may be supported by a type: procedure Op (O : in out T) is begin View_1_Op (View_1 (O'Access)); View_2_Op (View_2 (O'Access)); View_3_Op (View_3 (O'Access)); ... end; Contrary to being "obfuscated," implementing roles in Ada95 is quite simple and elegant. And no MI is required.