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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,efde8669839c1c0a,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!c37g2000yqi.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Proper program structure Date: Wed, 30 Sep 2009 14:25:57 -0700 (PDT) Organization: http://groups.google.com Message-ID: <638d582c-f275-48a9-aa2a-237f2edd123c@c37g2000yqi.googlegroups.com> NNTP-Posting-Host: 85.0.157.5 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1254345957 19095 127.0.0.1 (30 Sep 2009 21:25:57 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 30 Sep 2009 21:25:57 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c37g2000yqi.googlegroups.com; posting-host=85.0.157.5; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8546 Date: 2009-09-30T14:25:57-07:00 List-Id: First, thank you all for the replies to my previous questions. But I have more. :-) Consider the following example. It is imaginary, but shows the actual problem, even though the analogy is not always exact. package Cars is type Car (<>) is limited private; ... private type Car is limited record Body : ... Engine : ... Gear_Box : ... Wheels : ... end record; Note: in the actual project some of the components need to know about the others, but the "links" are always acyclic. To keep the sizes of all packages at a reasonable volume I decided to define each type in a separate package. The following shows the history of failures: 1. Some of the components of the car make sense in isolation and can be reused in other contexts, but some might be tied to the project with no chance for any reuse. Intuitively I thought they could be defined in private children of the Cars package (private means that users of Car will not use them by mistake and children to physically reflect the hierarchy). This is not possible, because the Cars package would need to "with" these private children packages and that introduces cyclic dependencies. Too bad. 2. Defining them in non-child packages means that they cannot see the complete structure of the Car and therefore they cannot be "wired" by discriminants like here: -- wrong: type Car is limited record Body : Body_Type (Car'Access); Engine : Engire_Type (Car'Access); -- and so on 3. So they have to be wired individually, but discriminants will still not work, as sibling components of the same record cannot be used to constrain each other: -- wrong: type Car is limited record Gear_Box : aliased Gear_Box_Type; Engine : Engire_Type (Gear_Box'Access); -- and so on 4. So they have to be wired individually by some initialization subprogram, presumably the Car's constructor function (because Car has a constructor function). There are two ways of doing it: 4a. By defining some Init procedure for each component type, which will establish the links. This means that all components are aliased and the Car's constructor function needs to call Init for each component and provide proper links to dependent components. I don't like the idea of having two-phase initialization and 'Unchecked_Access all over the shop, so this solution just sucks. 4b. By allocating all components dynamically and keeping them by access values. They can be allocated in the proper order with proper links to other components provided at the allocation time (there are no cycles, so there is always some proper order to do this), but then it does not look like a composition anymore and it is essentially "Java in Ada". In other words, all the solutions I can think of are either illegal or crappy. Am I over-sensitive or did I really hit a design problem? -- Maciej Sobczak * www.msobczak.com * www.inspirel.com Database Access Library for Ada: www.inspirel.com/soci-ada