home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!secapl!Cookie!frank
- From: frank@Cookie.secapl.com (Frank Adams)
- Subject: Re: Discriminating Variant Records Without switch() ??
- Message-ID: <1992Nov12.220050.94489@Cookie.secapl.com>
- Date: Thu, 12 Nov 1992 22:00:50 GMT
- References: <BAB.92Nov10073324@se39.wg2.waii.com> <1992Nov11.144253.26415@bnr.ca> <BAB.92Nov12074430@se39.wg2.waii.com>
- Organization: Security APL, Inc.
- Lines: 26
-
- In article <BAB.92Nov12074430@se39.wg2.waii.com> bab@se39.wg2.waii.com (Brian Button) writes:
- >->"Matthew" == Matthew Holiday <holiday@bnr.ca> writes:
- > Matthew> switch statement! :-) There ought to be a convenient way
- > Matthew> to create objects from network messages, i.e., some way to
- > Matthew> register message types and their matching class types,
- > Matthew> such that for every incoming message, its body (an array
- > Matthew> of bytes) gets turned into the correct object, which would
- > Matthew> be derived from a root generic message object.
- >
- >There is such a way using factory classes such as the RogueWave
- >RWFactory class. The problem I'm having is figuring out how to deal
- >with these objects after they are already created. Since there's no
- >common set of operations which are performed on each of the objects,
- >there is no set of methods which may be made virtual and overloaded.
- >Herein lies the problem. This seems to point towards using special
- >purpose code for each class, which would necessitate using a switch.
- >
- >Have I painted myself into a corner or is there some way out. How are
- >the rest of you OOP programmers dealing with cases like this?
-
- You are obviously reading these all in one place, so you must be doing
- *something* with them. Maybe just "handling" them -- which would suggest
- that the base class should have a virtual handle() method, which is
- implemented for each subclass to do whatever needs doing for that type of
- object. There may not be any other commonality -- if there isn't, don't try
- to force it where it doesn't exist.
-