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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,63fa88e2f1a3ebea X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!newspeer.monmouth.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Universal type in Ada Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1118928231.090737.170070@g44g2000cwa.googlegroups.com> Date: Thu, 16 Jun 2005 16:31:14 +0200 Message-ID: NNTP-Posting-Date: 16 Jun 2005 16:31:14 MEST NNTP-Posting-Host: 69044136.newsread2.arcor-online.net X-Trace: DXC=CX[6LHn;2LCV^7enW;^6ZC`T<=9bOTW=MN^ X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:11421 Date: 2005-06-16T16:31:14+02:00 List-Id: On 16 Jun 2005 06:23:51 -0700, zw@cs.man.ac.uk wrote: > Hi, thank you very much. This is a great idea to create pointers to an > Object. No, you don't need pointers. Create can return Object'Class which is much safer and easier to use. The example I gave, was to illustrate a language problem. In a real case the code looks different: function Create_My_Object (...) return Object_Handle is Result : Object_Ptr; begin Result := new My_Object (...); declare This : My_Object renames M_Object (Result.all); begin ... end; return Ref (Result); -- The result is a handle (for GC) exception when others => Free (Result); -- Don't want it leaking end Create_My_Object; Note the result is a handle instead of a raw pointer. This is closer to Java spirit, but not necessarily a universal solution. Not everything needs smart pointers. I wouldn't program a hard real-time application this way... (:-)) > I also have the same idea, but my problem is a pointer must be > declared with a specific type such as a pointer to an Integer. However, > in Ada, when we declared Object as an abstract superclass, the existing > types like Integer, Float, String are not an Object, we could easily > define a superclass called "Object" and define all of our types > inherited from the "Object", this way we will get roughly same > functionalities like Object as the root type. However, there is no way > to cope with existing types like Integer. Yes. You have to aggregate: type Integer_Object is new Object with record Value : Integer; end record; But, what are you looking for? Often people with a baggage of other languages are asking for a language-X solution in Ada. It is not the best way... > I would like to know that > whether this is possible to define a root type like "Object" in Java so > that whatever a "Method" is, it will always return an "Object"? because > all classes are inherited from "Object", so an Integer is an Object, a > Float is an Object, ........... Technically, this requires supertyping, which neither Ada nor Jave have. Though normally types like Integer, Float, Boolean etc need not to be "objects" in the sense that they all would have "Method" as a primitive operation. Also "objects" are usually thought as something large having identity. Well, this is wrong in general, but often right in particular. (:-)) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de