comp.lang.ada
 help / color / mirror / Atom feed
From: "Marc A. Criley" <mcqada95@earthlink.net>
Subject: Re: Package instance???
Date: Thu, 14 Feb 2002 12:48:23 GMT
Date: 2002-02-14T12:48:23+00:00	[thread overview]
Message-ID: <3C6BA502.1243FFED@earthlink.net> (raw)
In-Reply-To: OvBYEeMtBHA.1400@cpimsnntpa03

Yates wrote:
> 
> I am new to Ada. I'd like to know if it is possible to create multiple
> instances of a package. For example, if I have a package 'My_Package',  can
> I do something like:
> 
> p1 : My_Package := new My_Package
> p2 : My_Package := new My_Package
> .....
> 
> I tried this and didn't work. Is there other ways to do it?

I think you're perhaps thinking of a package as analogous to a C++
class.  While there are some surface similarities, packages and classes
embody different concepts.

Disregarding the other postings about generic packages, a package is an
encapsulation mechanism, i.e., a way to group data and functionality. 
The approximate equivalent of a C++ class is an Ada tagged type and its
primitive operations (a single set of which are normally grouped
together in a package).  If you wanted multiple instances of such a
"class", you would have multiple variable declarations of that tagged
type--or dynamically allocate them.  Packages serve to prevent making
all type (class) names globally visible, a capability that C++
namespaces was introduced to provide.

Because packages are not classes, there's more freedom about what they
can contain--constants, type definitions, supporting type definitions,
subprograms that are not directly associated with the package's tagged
type (but provide some functionality in support of it)--in short,
everything that's needed to define a class.  In this sense, a package is
more like a C++ file, which will contain the class definition as well as
the definitions and functions that aid the definition of the contained
class.  But the Ada package provides a stronger encapsulation of those
definitions than does a file.

Marc A. Criley
Consultant
Quadrus Corporation
www.quadruscorp.com



  parent reply	other threads:[~2002-02-14 12:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-13 19:48 Package instance??? Yates
2002-02-13 22:25 ` Zach Swanson
2002-02-13 22:31 ` Jeffrey Carter
2002-02-14  2:28   ` Zach Swanson
2002-02-14 14:32     ` Marin David Condic
2002-02-14  2:04 ` Bobby D. Bryant
2002-02-14  2:54 ` Steve Doiel
2002-02-14 14:41   ` Marin David Condic
2002-02-15  2:13     ` Steve Doiel
2002-02-14 12:48 ` Marc A. Criley [this message]
2002-02-14 15:09 ` Yates
2002-02-14 18:12 ` Matthew Heaney
replies disabled

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