Path: utzoo!censor!geac!becker!pantor!richard From: richard@pantor.UUCP (Richard Sargent) Newsgroups: comp.lang.c++ Subject: Novice question re: class derivation Message-ID: <44.UUL1.3#5109@pantor.UUCP> Date: 18 Jan 90 15:24:11 GMT Organization: Pansophic Systems Inc, Graphics Product Company Lines: 55 We have encountered a problem designing a tree of classes, that I hope someone out there can help resolve. I'm sure that it is just a case of looking at the problem "the wrong way", but I can't see the right way. [Apology: I'll use some PC terminology in the description, but the platform and hardware is not the problem, per se.] We want to be able to provide a base class called Display, which has derived classes for specific types of displays (such as Vista, Targa, VGA, raster file, etc.). Our first pass results in the following tree: Display | +--------+-----+--------+--------+ | | | | | Vista Targa VGA RasterFile etc. Now the problem comes when we try to code for the display device. Ideally, we want to be able to use an instance of class Display, so that our code is *written* device independent. We would like to simply code "Display device" and apply operations to "device", without concern for just which device it really is. The thinking is the constructor for class Display is able to determine what device it present and construct the appropriate class. An alternative, but less elegant solution, is to code something like the following, but I don't even know if this is valid: switch (inq_device_type()){ case dv_VISTA: Vista device; break; case dv_TARGA: Targa device; break; case dv_VGA: VGA device; break; . . . } So the bottom line is: How can I set up a hierarchy of device classes that will allow me to code (my main application, at least) to be independent of the display device? All help is appreciated. If any clarifications are needed, please ask. Thank you. Richard Sargent Internet: richard@pantor.UUCP Systems Analyst UUCP: ...!mnetor!becker!pantor!richard