Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbatt!ihnp4!chinet!nucsrl!gore From: gore@nucsrl.UUCP Newsgroups: comp.sys.amiga Subject: Re: Modula and C Message-ID: <3500004@nucsrl.UUCP> Date: Tue, 28-Apr-87 17:42:35 EDT Article-I.D.: nucsrl.3500004 Posted: Tue Apr 28 17:42:35 1987 Date-Received: Fri, 1-May-87 03:29:46 EDT References: <3242@jade.BERKELEY.EDU> Organization: Northwestern U, Evanston IL, USA Lines: 28 / nucsrl:comp.sys.amiga / hugo@gnome.cs.cmu.edu (Peter Su) / > [...] The big deal is, > that you can change the representation of the type arbitrarily, and as long > as the operations you give out still work, no code breaks. > > Note that Pascal and C, and Modula really don't let you do this very easily. > No matter what you do, whoever is using you library can always bypass your > interfaces and look directly at the bytes of the data structure, and this > causes bugs, and all sorts of nasty things. If you are talking about Modula-2 (which is what the rest of the discussion deals with), then this is one limitation that it doe NOT have. There is a reasonable way (maybe not great, but, in my book, acceptable) to dissassociate the implementation of an ADT (Abstract Data Type) from its specification. It uses what is called an "opaque type". Basically, you make the type you want to export (i.e., the type the users of your module will see) a pointer to a type you will actually use for implementation. You also export the routines you plan to provide. All of this happens in the specification part of the module. In the implementation part of the module, you actually declare the type that you plan to use in the implementation. Whoever is using the library cannot bypass your interfaces. Jacob Gore Northwestern University, Computer Science Research Lab {ihnp4,chinet}!nucsrl!gore