From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: ada and final/sealed classes
Date: Wed, 13 Oct 2004 15:31:07 +0200
Date: 2004-10-13T15:31:07+02:00 [thread overview]
Message-ID: <1a2ew6gzfwskx$.r1v3x4rptujz.dlg@40tude.net> (raw)
In-Reply-To: 1c2f5137.0410130438.3ea08553@posting.google.com
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
next parent reply other threads:[~2004-10-13 13:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1c2f5137.0410130438.3ea08553@posting.google.com>
2004-10-13 13:31 ` Dmitry A. Kazakov [this message]
2004-10-17 15:36 ` ada and final/sealed classes Matthew Heaney
2004-10-18 0:20 ` Brian May
2004-10-18 7:46 ` Martin Krischik
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox