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, T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b3e32a261c552ef1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-12-11 13:51:59 PST Path: supernews.google.com!sn-xit-02!supernews.com!isdnet!newsfeeds.belnet.be!news.belnet.be!news.tele.dk!129.240.148.23!uio.no!newsfeeds.sol.net!news.execpc.com!newspeer.sol.net!homer.alpha.net!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada References: <20001209101904.07653.00004016@ng-fy1.aol.com> Subject: Re: Ada OOP question X-Newsreader: Microsoft Outlook Express 4.72.3612.1700 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3719.2500 Message-ID: Date: Mon, 11 Dec 2000 15:52:50 -0600 NNTP-Posting-Host: 156.46.62.124 X-Complaints-To: abuse@alpha.net X-Trace: homer.alpha.net 976571512 156.46.62.124 (Mon, 11 Dec 2000 15:51:52 CST) NNTP-Posting-Date: Mon, 11 Dec 2000 15:51:52 CST Xref: supernews.google.com comp.lang.ada:2958 Date: 2000-12-11T15:52:50-06:00 List-Id: James S. Rogers wrote in message ... >The question clearly comes from a person who has learned C++ or Java. >Those languages allow classes to be defined with mixtures of public and >private data. > >The same effect can be achieved in Ada, although the syntax is not as clean >as in C++ or Java. > >A tagged type in Ada is defined either in the public or private area of a >package specification. It is not defined partially in the public area and >partially in the private area. At first glance this seems to forbid creating a >tagged type with both public and private data members. There is a solution. > >In Ada you need to extend the inheritance hierarchy a little deeper to >achieve your goals. Follow these steps: > >1) Declare a tagged type in the public part of a package specification. >2) Extend that tagged type with a private extension in the private part of a > child package specification. >3) Inherit all future tagged types in that class from the child package with the > private definition. It's not necessary to create a separate package for the extension (IF you're careful with the placement of primitive operations). This is an important difference between C++ and Ada (since the encapsulation and inheritance mechanisms are separate in Ada). If your only purpose is to have both kinds of components, make the original type abstract so no one can accidentally create an object of it (without the private components): (We use this technique in Claw to hide locks associated with some objects...) package Employee_Package is type Public_Employee is abstract tagged record -- No objects of this are allowed. Name : String(1..30); Age : Positive; Employee_Id : String(1..8); Title : String(1..20); end record; type Employee is new Public_Employee with private; -- Follow with public subprograms appropriate to -- the above tagged type definition private type Employee is new Public_Employee with record Salary : Float; end record; end Employee_Package; >Every instance of the Employee tagged type, or any instance in its >class hierarchy, will have both public and private data members. Randy Brukardt R.R. Software, Inc.