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.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,12a63150f4f961a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.239.134 with SMTP id vs6mr2349126pbc.4.1336127822755; Fri, 04 May 2012 03:37:02 -0700 (PDT) Path: pr3ni2701pbb.0!nntp.google.com!news2.google.com!goblin3!goblin.stu.neva.ru!news.tu-darmstadt.de!news.belwue.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Fri, 04 May 2012 12:37:01 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: OOP in Ada: Alternatives for "protected" scope References: In-Reply-To: Message-ID: <4fa3b14b$0$6555$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 04 May 2012 12:36:59 CEST NNTP-Posting-Host: 77c78de6.newsspool4.arcor-online.net X-Trace: DXC=aI94hP\AM\fUoRk[hk2Wal4IUKejVhKnjIfRO6W3`O1]oM0d]Doo X-Complaints-To: usenet-abuse@arcor.de Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-05-04T12:36:59+02:00 List-Id: On 03.05.12 23:27, Felix Krause wrote: > Now there is some calculation to be done while execution Do_Something which cannot be defined in A. > (...) > In languages like Java and C#, there is a "protected" scope to cope with this situation. There are some O-O solutions. One solution is outlined by at least on Java guru, and by the Objective-C programming model in ***step. In short, replace procedural style with O-O style (sounds odd, but that's really what it does; the dependence of A/Do_Something on Calculate is an implicit procedural thing). with Calculators; package P_A is type A is abstract tagged private; procedure Do_Something (Object : in out A); -- -- Add your type of computation here to be performed -- at some time during the execution of Do_Something: -- procedure Link (Object : in out A; Computation: Calculators.Calculator'Class); private type Circuits is access constant Calculators.Calculator'Class; type A is abstract tagged record Machine : Circuits; end record; end P_A; If necessary things can be moved further down the package and/or type hierarchy if the presence of a calculation should be hidden at the top level.