11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

288Part IV: Inheritanceclass Display{public:virtual void initialize( ) = 0;virtual void write(char *pString) = 0;};class SVGA : public Display{// override both member functions with “real” functionsvirtual void initialize( );virtual void write(char *pString);};class HWVGA : public Display{// override the only function we know how to up until nowvirtual void write(char *pString);};class ThreedVGA : public HWVGA{virtual void initialize( );};void fn( ){SVGA mc;ThreedVGA vga;// ...what the function chooses to do from here...}The class Display, intended to represent video PC displays, has two purevirtual functions: initialize() and write(). You can’t implement eitherfunction for adapters in general. The different types of video cards do not initializeor write in the same way.One of the subclasses, SVGA, is not abstract. This is a particular type of videoadapter that the programmer knows how to program. Therefore, the classSVGA has overridden both initialize() and write() appropriately for thisadapter.HWVGA, another one of the subclasses, is also not abstract. Here again, theprogrammer knows how to program the accelerated VGA adapter hardware.In this case, however, a level of abstraction is between the generic Displayand the specific case of the ThreedVGA display, which represents the special3-D hardware display cards.For this discussion, assume that all hardware-accelerated VGA cards are writtento in the same way, but that each must be initialized in its own way. (This

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!