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,f45075a84ed4f2fc,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-02 15:06:50 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.cidera.com!cyclone1.gnilink.net!news-east.rr.com!news-west.rr.com!lsnws01.we.mediaone.net!cyclone-LA3.rr.com!typhoon.san.rr.com.POSTED!not-for-mail Message-ID: <3B69CEF7.9BAD41C8@san.rr.com> From: Darren New Organization: Boxes! X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: A question about extending programs Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Thu, 02 Aug 2001 22:06:47 GMT NNTP-Posting-Host: 24.165.21.192 X-Complaints-To: abuse@rr.com X-Trace: typhoon.san.rr.com 996790007 24.165.21.192 (Thu, 02 Aug 2001 15:06:47 PDT) NNTP-Posting-Date: Thu, 02 Aug 2001 15:06:47 PDT Xref: archiver1.google.com comp.lang.ada:11147 Date: 2001-08-02T22:06:47+00:00 List-Id: I have a question about extending Ada OO programs. I find that a great deal of the programs I write wind up being a skeleton with code for a bunch of different cases, and those cases tend to expand over time. For example, a transaction processor with transactions getting added, a GUI with menu options getting added, etc. In all these cases, there's generally a mapping from something like a string to something like a class: the transaction name mapping to a function that handles it, the MIME type mapping to the plug-in that displays it, etc. Take a specific example, which I hope is mostly right. I have a list of file names. Each file has a particular extension. The extension tells you the file format. Each format has a different way of generating a thumbnail image. In a more dynamic language (Java, Tcl, etc) where one can easily load code on the fly, I generally map between file extensions and the name of the file holding the code to handle that extension. This obviously won't work (as easily) in Ada, but I don't mind relinking to add more functionality. For Ada, I'm postulating the existance of a "Register" procedure, which would (in this example) take a String representing the file extension and an access-to-procedure (or classwide type or something) and add it to the list of known file extensions and how to handle them. It seems clear to me that each image format handler should be in its own package, and that the package body should call the Register routine to register itself. Then adding a new image type handler consists of implementing the routine to make thumbnails etc and adding a call to "Register" in the package body, so it gets called when the package is elaborated. With me so far? OK, good. Say I have three such handlers in my program now. Is it possible to add a forth without changing any source that's already there? The real question that I think I need to have answered is, how do I force the fourth handler to get linked in and elaborated without a specific call in the main body area that references the handler? In other words, there's nothing that "with"s the package. Do I actually have to have a list of "with" statements, one for each package, somewhere? Do I need to actually call something, or is "with" sufficient? I suppose I could "with" a package from the main routine that "withs" all the other packages, thereby basically building a list of things I handle. Is that the best way? As always, TIA for any suggestions! -- Darren New / Senior MTS & Free Radical / Invisible Worlds Inc. San Diego, CA, USA (PST). Cryptokeys on demand. dnew@san.rr.com Only a WIMP puts wallpaper on his desktop.