Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bionet!agate!ucbvax!hplabs!hp-ses!hpcuhb!hpindda!hardin From: hardin@hpindda.HP.COM (John Hardin) Newsgroups: comp.lang.c++ Subject: Re: Objectifying incoming messages? Message-ID: <6170009@hpindda.HP.COM> Date: 28 Jul 89 16:35:08 GMT References: <444@cimshop.UUCP> Organization: HP Information Networks, Cupertino, CA Lines: 27 dog@cbnewsl.ATT.COM (edward.n.schiebel) writes: > From article <444@cimshop.UUCP>, by davidm@cimshop.UUCP (David Masterson): > > The fundamental question hinges around the lack of context of the incoming > > message. Therefore, the message user must look at the data in order to > > determine what to coerce (definition?) the message into. Is this appropriate > > or is there a better way? > > > The same problem arises reading objects from disk. Until you look at > the data, you don't know what class of object to instance so it > can read itself. It seems to me, this is one place you still > need a header/type field and a switch statement. >---------- Reading objects from disk is exactly the subject of one of the demo programs that comes with Borland's Turbo Pascal 5.5 (with object oriented extentions). I haven't looked at it in detail, but I believe they derive classes from their stream class and then the derived classes are somehow "registered" with the stream class. A get from the stream then first reads the next object type and calls the "get" method of that class. This embeds the switch within the steam's "get" method. BTW, I believe the demo is called CARDFILE. Has anyone else looked at this? If you have, what do you think of it? John Hardin hardin%hpindgh@hplabs.hp.com --------