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-Thread: 103376,92a5558d9ff5b0f2,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: ada and final/sealed classes Date: Wed, 13 Oct 2004 15:31:07 +0200 Message-ID: <1a2ew6gzfwskx$.r1v3x4rptujz.dlg@40tude.net> References: <1c2f5137.0410130438.3ea08553@posting.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de mqKysojqzny/sa82KFA9jAr8SLefQNjB6Oz4y3zJcCcXt6jao= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:5150 Date: 2004-10-13T15:31:07+02:00 List-Id: On 13 Oct 2004 05:38:32 -0700, Hans Van den Eynden wrote: > I want to prevent that someone inherits from a type I made (for > security purposes). 1. When the public view of the type is untagged, then it is impossible to extend it publicly: package Foo is type Final is private; procedure Baz (Object : Final); private type Final is tagged null record; Only children of the package Foo know that Final is tagged. Therefore: with Foo; package Unrelated is type Illegal is new Foo.Final with null record; -- Error 2. A less brutal approach: a) The primitive operations can be made private; b) other operations, especially class-wide ones, are always "final": package Foo is type Has_Secret_Methods is tagged ...; procedure Final (Object : in out Has_Secret_Methods'Class); private procedure Secret (Object : in out Has_Secret_Methods); Here Final is a class-wide procedure. As such it cannot be overridden. Secret is not visible for public clients and so cannot be overridden by those. 3. For happy owners of ergonomic keyboards: you can always use aggregation. However the language will not help you in creating wrappers, so train your fingers: package Private_Foo is type Unsealed is tagged ...; procedure Baz (X : Unsealed); end Private_Foo; with Private_Foo; package Public_Foo is type Sealed is private; -- non-tagged wrapper procedure Baz (X : Sealed); -- Proxy pragma Inline (Baz); private use Private_Foo; type Sealed is record Thing : Unsealed; end record; ---- procedure Baz (X : Sealed) is begin Baz (X.Thing); end Baz; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de