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,7137ee7358078d09 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!npeer.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Basic Explaination of OO in Ada Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.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: <1158593087.194781.250030@e3g2000cwe.googlegroups.com> <1158636734.971377.112550@d34g2000cwd.googlegroups.com> <1158674185.887102.205150@m73g2000cwd.googlegroups.com> <1158675056.233248.223870@e3g2000cwe.googlegroups.com> <1158675806.550148.278060@b28g2000cwb.googlegroups.com> Date: Tue, 19 Sep 2006 17:45:21 +0200 Message-ID: <1tb2yi8ffs9zr.ktlycn8no6jh.dlg@40tude.net> NNTP-Posting-Date: 19 Sep 2006 17:45:21 CEST NNTP-Posting-Host: a29b08c3.newsspool2.arcor-online.net X-Trace: DXC=Tkj:kMDBcmO^B]`=U:WelBA9EHlD;3YcB4Fo<]lROoRA4nDHegD_]REBWg;OT?eX9HDNcfSJ;bb[EFCTGGVUmh?DN\HXHJ4e80NV9`a7m`JCGH X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:6669 Date: 2006-09-19T17:45:21+02:00 List-Id: On 19 Sep 2006 07:23:26 -0700, richard.charts@gmail.com wrote: > Lucretia wrote: >> richard.charts@gmail.com wrote: >>> One thing I'm still confused on is the use of access objects >> >> An access type is equivalent to a pointer in C, although an access type >> in Ada may or may not be an actual address, it could be an offset into >> a block of memory. >> >> Luke. > > I understand that part, but I do not see how an access type could be > used to handle polymorphism. Unless that is the point. Same as objects pointers can be specific and class-wide. So: Specific Class-wide (=polymorphic) Object T T'Class Pointer access T access T'Class Polymorphic things, be they pointers or objects, natively support dispatch. Therefore a dispatching subprogram (= in Ada terms "primitive") can be defined for both. type T is tagged ...; procedure Foo (X : T); procedure Bar (X : access T); Foo and Bar are primitive. They both are defined on the class. This means that each member of T'Class "has" Foo and each member of access T'Class "has" Bar. Foo and Bar are said dynamically polymorphic = dispatching = virtual in C++ terms = primitive operations in Ada terms. The implementation of Foo and Bar consists out of many type-specific implementations. So each type derived from T has some part of the body of Foo. This part is either inherited from the base type or overridden. Class-wide subprograms are also defined on the class: procedure Foo (X : T'Class); procedure Bar (X : access T'Class); But they have the same body for all members of the class = they don't dispatch (you don't need to if the body is same). > or (as I am scrolling through Ada Distilled) is it that I am > misunderstanding Storage Pool Access Type vs General Access Type? General access type = the object can be in any pool. Pool access = object can only be in a specific pool. In this sense, yes, general access pointers dispatch on the actual pool. If the target type is polymorphic they also dispatch on that. So access T is "double dispatching." Ada offers all four combinations of access types regarding polymorphism against the target type and the pool type: T Pool type T_Ptr is access T specific specific type T_Ptr is access T'Class class-wide specific type T_Ptr is access all T specific class-wide type T_Ptr is access all T'Class class-wide class-wide > Is it possible to for object_type to handle either object or sub_object? No. It must be object_type'Class. When S is derived from T, then T'Class can hold T and S. But T and S are different types, and no object can be of two types at the same time. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de