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,FILL_THIS_FORM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.224.215.68 with SMTP id hd4mr12205473qab.5.1371804185623; Fri, 21 Jun 2013 01:43:05 -0700 (PDT) X-Received: by 10.49.62.3 with SMTP id u3mr264433qer.26.1371804185599; Fri, 21 Jun 2013 01:43:05 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!mx05.eternal-september.org!feeder.eternal-september.org!news.bbs-scene.org!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!bw2no2522537qab.0!news-out.google.com!y6ni3811qax.0!nntp.google.com!j2no1069914qak.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 21 Jun 2013 01:43:05 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=20.133.0.8; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G NNTP-Posting-Host: 20.133.0.8 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <69246de0-4b33-4d47-b5be-a45e8c911fb0@googlegroups.com> Subject: Ada202X: Easy to use "UML private"-like components From: Martin Injection-Date: Fri, 21 Jun 2013 08:43:05 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:15869 Date: 2013-06-21T01:43:05-07:00 List-Id: I occasionally have the need to explain to people that Ada can support UML public, protected, private class data member scoping but to say it's confusing and clunky would be putting it mildly... Firstly, I have to public - that's easy: package CLA is type UML_Public is tagged record I : Integer; -- public to all, UML "public" F : Float; end record; end CLA; Secondly, I have to explain that using Ada "private" gives you "UML protected": package CLA is type UML_Protected is tagged private; private type UML_Protected is tagged record I : Integer; -- private to everyone excepted derived, UML "protected" F : Float; end record; end CLA; Finally, I have to explain that to get "UML private", you need to use an "opaque type" and and "access type": package CLA is type UML_Private is tagged private; private type Opaque; type UML_Private is tagged record I : Integer; -- private to everyone excepted derived, UML "protected" O : access Opaque; -- has to be access, as compiler doesn't -- know what Opaque is! end record; end CLA; package body CLA is type Opaque is record I : Integer; -- private to everyone, UML "private" F : Float; end record; end CLA; By now, the other person is usually rolling their eyes in disbelief and I'm nearly joining them... There's nothing we can do about Ada "private" v UML "protected" but I think there is a relatively small addition that could be made to the language that would at least avoid the embarrassment of the third part. My proposal would be to allow an optional "private component list" to record definitions, e.g. package CLA is type UML_Private is tagged private; private type UML_Private is tagged record I : Integer; -- private to everyone excepted derived, UML "protected" private F : Float; -- private to everyone - even derived, UML "private" end record; end CLA; Where a record had nothing but private components, it could either use: Option 1: type T is tagged record private F : Float; end record; or Option 2: type T is tagged record null; private F : Float; end record; I prefer Option 2. Thoughts? -- Martin