BRYAN@SU-SIERRA.ARPA (Doug Bryan) (09/13/85)
Hello expert Ada designers, I could use your suggestions. This is the design problem: Consider a heavily layered system. One of the lower level packages exports a limited type. The higher levels are all abstractions of the operations avaiable at all lower levels. Thus higher level packages must reference the limited type and will export operations in this reference. The reference will be used in all parameter modes. The problem is, what type do the higher level packages use to reference the lower level limited type? For example: with text_io; package file_stuff is type a_file is limited private; procedure x (file : in out a_file); ... private type a_file somehow maps to text_io.file_type; end file_stuff; I have been using access types: type a_file is access text_io.file_type; This method has its limitations, for instance if the implementation of the limited type is an unconstrained record (all objects created using allocation are contrained). Another method involves arrays: private max_files : constant := 100; type a_file is range 1 .. max_files; ... package body file_stuff is the_files : array (a_file) of text_io.file_type; ... The limitations to the array solution are obvious: fixed max number of objects, lots of memory used when it may not need be ( of the user only needs 2 files).... what do you think?? doug -------
GBOOCH@USC-ECLB.ARPA (09/13/85)
For a heavilylayered system in which abstractions are built on top of abstractions (and each layer hids its implementation), I tend to use either access types (occasionally) or derived types (most often). thus, in your example of the package file_stuff, I would probably write the full type declaration for a_file as: type a_file is new text_io.file_type; This actually is a common issue (i.e. how tdo I get the implementation of a private type to map excatly to another type). It would be nice (sometimes) to have a fully type declaration in the private part as a subtype, rather than a type, but Ada prevents this (and for good reason, I believe...the alternative produces some strnage problems). egb -------