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-Thread: 103376,c4f3d9c0fed1bd8f,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!130.59.10.21.MISMATCH!kanaga.switch.ch!news-zh.switch.ch!switch.ch!cernne03.cern.ch!cern.ch!news From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Classes and packages - recommended practice Date: Mon, 12 Dec 2005 14:19:13 +0100 Organization: CERN - European Laboratory for Particle Physics Message-ID: NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sunnews.cern.ch 1134393552 15439 (None) 137.138.37.241 X-Complaints-To: news@sunnews.cern.ch User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050922 Red Hat/1.7.12-1.1.3.2.SL3 X-Accept-Language: en-us, en Xref: g2news1.google.com comp.lang.ada:6849 Date: 2005-12-12T14:19:13+01:00 List-Id: Hi, Let's take the basic example with three types: - Shape (abstract) - Triangle - Rectangle I have learnt three options to represent them as packages. Let's choose the Objects/Object naming convention for the package and the actual type - this is the first convention presented in: http://en.wikibooks.org/wiki/Ada_Programming/Object_Orientation#Class_names 1. Make a separate package for each class. This means that there are 6 files (3x ads + 3x adb). None of the packages is a child or nested withing another. The client code may do the following to be able to use all names without qualification: with Shapes; use Shapes; with Triangles; use Triangles; with Rectangles; use Rectangles; 2. Make a root package Shapes and have the leaf classes in child packages. This means that there are still 6 files. The client code may do this: with Shapes; use Shapes; with Shapes.Triangles; use Shapes.Triangles; with Shapes.Rectangles; use Shapes.Rectangles; 3. Make a single package Shapes and have two *nested* packages for Triangles and Rectangles. This means that there are only two files (shapes.ads and shapes.adb). The client code may do this: with Shapes; use Shapes; use Shapes.Triangles; use Shapes.Rectangles; My question is - when do you use which form? The third options seems nice because it is compact. Not only there are just two files to mess with, but the "locality of reference" (in the sense of reading the source code) is higher when the whole hierarchy can be viewed in a single place. The problem is that this seems to be applicable only to closed hierarchies, when no new classes are likely to be added. Still, there are cases when that's exactly the case (for example, when the set of derived classes completely partition the superclass). Second option (with child packages) seems interesting, because it is open for extension (no need to edit existing files when adding new sibling classes), and at the same time the relations between classes are expressed in package names (and file names) as well, which can ease navigation in the project. First option is, well, ... so what would you say about the first option? What do you recommend and when? Are the issues above the only ones that can be taken into account? Regards, -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/