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-Thread: 103376,da9f9995bafb51df X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.74.201 with SMTP id w9mr7788441pbv.0.1333749021039; Fri, 06 Apr 2012 14:50:21 -0700 (PDT) Path: r9ni26626pbh.0!nntp.google.com!news1.google.com!goblin2!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Assigning a "subclass" instance to a "superclass" variable Date: Fri, 06 Apr 2012 22:50:18 +0100 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="25716"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193V1OuFKFMLlvG34V1tOSfK7zBw3H9Sww=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (darwin) Cancel-Lock: sha1:O1KW/ht1vh/BtMDEObx/cruO3bU= sha1:pH8HJS4ld0d0T2b7AU1ENsyRIWU= Content-Type: text/plain; charset=us-ascii Date: 2012-04-06T22:50:18+01:00 List-Id: deuteros writes: > I'm still trying to understand how Ada does object orientation. In > Java I could do this: [...] > So in Ada I'm trying to achieve something similar with my Statement > package: > > package Statements is > > type Statement is abstract tagged > record > tokens : Vector; > executedtokens : Vector; > end record; > > type Statement_Access is access all Statement'Class; > > function execute(skip: in Boolean; S: in Statement) return Integer is abstract; > > end Statements; > > So when I create a child of Statement, how to I set up the .ads file? with Statements; package Expressions is type Expression is new Statements.Statement with record ... end record; function Execute (Skip : Boolean; S : Expression) return Integer; end Expressions; or package Statements.Expressions is type Expression is new Statement with record ... end record; function Execute (Skip : Boolean; S : Expression) return Integer; end Statements.Expressions; The second form is good if the full declaration of Statement is in the private part of Statements, since child packages can see the private parts of their parents.