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-15 02:22:15 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!ucberkeley!feed.news.qwest.net!namche.sun.com!news1nwk.sfbay.sun.com!new-usenet.uk.sun.com!not-for-mail From: olehjalmar kristensen - Sun Microsystems - Trondheim Norway Newsgroups: comp.lang.ada Subject: Re: Is the Writing on the Wall for Ada? Date: 15 Sep 2003 11:19:50 +0200 Organization: Sun Microsystems Inc., http://www.sun.com/ Message-ID: References: NNTP-Posting-Host: khepri06.norway.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: new-usenet.uk.sun.com 1063617591 23604 129.159.112.195 (15 Sep 2003 09:19:51 GMT) X-Complaints-To: usenet@new-usenet.uk.sun.com NNTP-Posting-Date: 15 Sep 2003 09:19:51 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:42516 Date: 2003-09-15T09:19:51+00:00 List-Id: >>>>> "MH" == Matthew Heaney writes: MH> 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. MH> The mechanism for implementing roles (what we call "views") in Ada95 is MH> access discriminants, not MI. MH> For example, if I want to have a "persistence role," I can do this: MH> package Persistence_Views is MH> type Root_Persistence_Type is MH> abstract tagged limited null record; MH> type Persistence_Class_Access is MH> access all Root_Persistence_Type'Class; MH> procedure Write MH> (Stream : in out Root_Stream_Type'Class; MH> Persistence : access Root_Persistence_Type) is abstract; MH> procedure Read MH> (Stream : in out Root_Stream_Type'Class; MH> Persistence : access Root_Persistence_Type) is abstract; MH> procedure Save MH> (Persistence : access Root_Persistence_Type'Class); MH> end Persistence_Views; MH> To add support for persistence to a type, you can do this: MH> with Persistence_Views; MH> package P is MH> type T is tagged limited private; MH> function Persistence (O : access T) MH> return Persistence_Class_Access; MH> ... MH> private MH> type Persisence_Type (O : access T) is MH> new Root_Persistence_Type with null record; MH> procedure Write (...); MH> procedure Read (...); MH> type T is tagged limited record MH> Persistence : aliased Persistence_Type (T'Access); MH> ... MH> end record; MH> end P; MH> So now given an object of type T (which supports persistence), you can MH> oo this: MH> procedure Op (O : in out T) is MH> begin MH> Save (Persistence (O'Access)); MH> end; MH> We've shown one role here, but in fact any number of views may be MH> supported by a type: MH> procedure Op (O : in out T) is MH> begin MH> View_1_Op (View_1 (O'Access)); MH> View_2_Op (View_2 (O'Access)); MH> View_3_Op (View_3 (O'Access)); MH> ... MH> end; MH> Contrary to being "obfuscated," implementing roles in Ada95 is quite MH> simple and elegant. And no MI is required. But this is not exactly what I was talking about. With MI, you may inherit both interface and implementation, no need to write new code. It's all about synthesising new object types from existing ones without the straightjacket of single inheritance.