Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uwm.edu!bionet!arisia!sgi!shinobu!odin!delrey!shap From: shap@delrey.sgi.com (Jonathan Shapiro) Newsgroups: comp.lang.c++ Subject: Re: Novice question re: class derivation Message-ID: <2995@odin.SGI.COM> Date: 19 Jan 90 18:46:19 GMT References: <44.UUL1.3#5109@pantor.UUCP> Sender: news@odin.SGI.COM Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 32 In article <44.UUL1.3#5109@pantor.UUCP> richard@pantor.UUCP (Richard Sargent) writes: >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? > >Richard Sargent Internet: richard@pantor.UUCP >Systems Analyst UUCP: ...!mnetor!becker!pantor!richard Right idea. Wrong implementation. By the time you hit the Device constructor, you are essentially saying that you already are constructing the appropriate kind. What is needed is a single library routine that determines the device type, allocates the right kind, and returns a Device *: Device * getDevice() { kind = determine_which_graphics_head(); switch(kind) { case Targa: return new Targa; case Wombat: return new Wombat; ... } return 0; } Jonathan Shapiro Silicon Graphics, Inc.