comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: advice on package design
Date: Tue, 8 Mar 2005 18:18:25 +0100
Date: 2005-03-08T18:18:22+01:00	[thread overview]
Message-ID: <1czv12sp1pfai.ieuftfegplth$.dlg@40tude.net> (raw)
In-Reply-To: 1110286121.068133.82160@l41g2000cwc.googlegroups.com

On 8 Mar 2005 04:48:41 -0800, spambox@volja.net wrote:

> Dmitry A. Kazakov wrote:
> 
>> There are many different ways to deal with that. If you have
> 
> Dmitry, thank you very much for you help; this is the second time that
> you've posted elaborate answers to my problems. I apreciate it.

You are welcome.

>> 2. You can instantiate your Baz outside Foo but with the things
>> defined in the public part of Foo:
> 
>> Note that the body of Foo may still use Baz:
> 
> My thoughts on this solution: the package would have to know how the
> user chose to instantiate another package, so that it could use the
> same name. On the other hand, let's say the package came with
> instructions as to how the package it depends on should be
> instantiated.

Ada also has formal generic packages. If Foo has to be dependent on an
instantiated by user Bar, then you can make it generic:

generic
   type Word is ...;
   with package Baz is new Bar (Word, ...);
package Foo is ... end Foo;

Though this would inverse the dependency between Foo and Baz.

> However, that would leave the user no choice for the name
> and effectively we would get something similar to your first solution.
> I find this approach better; the package `a' comes with instructions,
> directing the user to "use" something that was instantiated in `a' with
> the same name, of course. Sure, it could also be renamed later.
> 
>> 3. You can rename parts of contents of Baz in Foo:
> 
> At present, this is the accepted solution. It seems to me that it's
> also the most logical for ada?

Be careful. Ada community is deeply divided on this issue! (:-)) There are
people who depreciate use of use. Sorry for an unintended pun. (:-)) I am
not among them.

> Since we're forced to follow the rules
> of strong typing, then it's only logical to have different subroutines
> for each type. There are only less than ten subroutines in my linked
> lists package, so renaming then was easy. Besides, the program becomes
> clearer (in the end, that's what ada encourages us to do, right?) --
> now, for example, we can use a word_walk subroutine for word lists, and
> eg. node_walk for all the others. Agreed, a good idea.

Though it is probably not your case, but just to complete the picture...
Ada supports implementation through renaming. For example, the following is
legal:

package Foo is
   type Word is ...
   procedure Insert (...);

private
   package Baz is new Bar (Word, ...); -- They won't see it
   procedure Insert (...) renames Baz.Insert;
      -- Insert is implemented through renaming of a procedure
   ...
end Foo;

This way you can hide the fact of instantiation of Bar and that Insert is
implemented in Bar. Unfortunately it does not work with types. There is no
type renaming in Ada. Subtyping and deriving a new type sometimes can do
the trick, sometimes not.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2005-03-08 17:18 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-07 16:23 advice on package design spambox
2005-03-07 21:08 ` Dmitry A. Kazakov
2005-03-08 12:48   ` spambox
2005-03-08 17:18     ` Dmitry A. Kazakov [this message]
2005-03-12 19:57   ` Robert A Duff
2005-03-12 20:45     ` Dmitry A. Kazakov
2005-03-12 21:59       ` Robert A Duff
2005-03-13  9:23         ` Dmitry A. Kazakov
2005-03-16 20:41           ` Robert A Duff
2005-03-17 10:22             ` Dmitry A. Kazakov
2005-03-17 14:04               ` Robert A Duff
2005-03-17 15:59                 ` Dmitry A. Kazakov
2005-03-17 19:10                   ` Robert A Duff
2005-03-17 19:47                     ` Martin Dowie
2005-03-17 20:55                       ` Robert A Duff
2005-03-17 21:14                         ` Marius Amado Alves
2005-03-18  9:31                           ` Martin Dowie
2005-03-18  9:38                         ` Martin Dowie
2005-03-21 16:19                           ` Robert A Duff
2005-03-17 20:48                     ` Dmitry A. Kazakov
2005-03-17 21:26                       ` Robert A Duff
2005-03-18  3:06                         ` Jared
2005-03-18 10:00                         ` Dmitry A. Kazakov
2005-03-21 16:17                           ` Robert A Duff
2005-03-21 18:16                             ` Dmitry A. Kazakov
2005-03-21 20:35                               ` Robert A Duff
2005-03-22 10:55                                 ` Dmitry A. Kazakov
2005-03-17 23:23                 ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox