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 18:24:09 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi_feed4!attbi.com!sccrnsc01.POSTED!not-for-mail Message-ID: <3F6514A2.4050009@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: Can MI be supported? (Was: Is the Writing on the Wall for Ada?) References: <3F5F7FDC.30500@attbi.com> <3F636281.7010509@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: sccrnsc01 1063589048 24.34.139.183 (Mon, 15 Sep 2003 01:24:08 GMT) NNTP-Posting-Date: Mon, 15 Sep 2003 01:24:08 GMT Organization: Comcast Online Date: Mon, 15 Sep 2003 01:24:08 GMT Xref: archiver1.google.com comp.lang.ada:42506 Date: 2003-09-15T01:24:08+00:00 List-Id: Warren W. Gay VE3WWG wrote: > So why not add "has a" test? Then you could test if instance V "has a" > X, Y or Z component. You could also say that V is "not is a" X, Y or Z, > since clearly it is not any one of them by themselves. I don't know that I would call it "has a" but that is exactly what mix-ins do. But I have wondered whether we got mix-ins too right in Ada 95. I just saw a post by Matt Heaney on access discriminants. There are some roles for which the mix-in needs access to the whole object, and his particular example (persistant types) is one of them. But for most roles where a role only needs access to its own state variables, mix-ins do the job nicely and much more elegantly than access discriminants. But some programmers miss this easy way because it is too easy and too elegant. In the example I gave (a complete executable example) the mix-ins added state variables of type Color and Size to a type, with Get and Set operations for each. I did this deliberately because some people worry about view conflicts with multiple inheritance. But this is Ada! The operations overload each other, and potentially additional operations of the same name on the object type, but the strong typing means that Set(Some_Object, Red) and Set(Some_Object, Small) will not conflict. You can even, and I have done this, instantiate the same mix-in twice on the same base type. I was implementing two-dimensional sparse arrays as linked lists. One mix-in added row links, one added column links, and if I wanted to add a (non-zero) element to a sparse matrix, I said: Add(Entry, Some_Matrix, Row_Number); Add(Entry, Some_Matrix, Column_Number); And overload resolution took care of the rest. Since Rows and Columns were separate types derived from Integer, I couldn't even try to mix them up. This may sound like I was doing linear algebra on the sparse arrays, and to some extent I was. But the entries were actually records with about 160 bytes of data, and I was doing row and column permutation operations and vector operations where this representation was perfect. The linked lists didn't have to be in any particular order. -- "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