Here is a real world scenario that may best answer your question.
ABC
Now you have the construct for what any Image would look like. From here out, all your derived classes may do things entirely different. For example, you may have a JPEGImage class which stores a JFIF header and has to decode data in order to getPixels(). Or you may have a BitmapImage that is just a fat array of pixels that are ready to be dumped as-is.Code:class Image { public: virtual void *getPixels() = 0; virtual void setPixels(void *pxls); virtual size_t getWidth() const = 0; virtual size_t getHeight() const = 0; virtual void setWidth(size_t width) = 0; virtual void getHeight(size_t height) = 0; };
Since you have a reliable interface that is consistent across the board, it does not matter how things are dealt with internally. Right? That is more what encapsulation is about rather than "hiding data" as some may say. Its not a matter of hiding so much as its a matter of I do not care how you store your pixels, I just need to see them so I can draw to the screen.