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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,95971bf29a745ff4 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-02-14 04:48:33 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!rcn!newsfeed1.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3C6BA502.1243FFED@earthlink.net> From: "Marc A. Criley" Organization: Quadrus Corporation X-Mailer: Mozilla 4.73 [en] (X11; U; Linux 2.2.14-5.0 i686) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Package instance??? References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Thu, 14 Feb 2002 12:48:23 GMT NNTP-Posting-Host: 158.252.123.200 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1013690903 158.252.123.200 (Thu, 14 Feb 2002 04:48:23 PST) NNTP-Posting-Date: Thu, 14 Feb 2002 04:48:23 PST X-Received-Date: Thu, 14 Feb 2002 04:48:23 PST (newsmaster1.prod.itd.earthlink.net) Xref: archiver1.google.com comp.lang.ada:20000 Date: 2002-02-14T12:48:23+00:00 List-Id: 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