With this design approach, it is possible to reuse the code - the general code applicable to all ImageFiles can be moved to that class. Now, if there is any need to refer to specific types - for example, when converting from one image type to another - we can use specific file types such as JPEGFile, SVGFile, etc. With this design, when we want to write high-level code - for example, reading the file from the disk - we can write code in terms of the generic type ImageFile. Further, RasterFormat can have derived classes such as JPEGFile, TIFFFile, PNGFile, etc., and VectorFile can have derived classes such as CGMFile, SVGFile, etc. In other words, we can have a base class named ImageFile, and two derived classes, namely, RasterFile and VectorFile. This allows for abstracting commonalities of the specific file format, and moving the specific details of a file format to that class. For example, in an image-processing application, instead of writing code in terms of different kinds of image files such as GIF, JPEG, EPS, SVG, PNS, etc., one can exploit the commonalities between the image file formats.įor example, we can classify image types at a higher level as raster (storing images as bitmaps, or in terms of pixels), or vector (geometric description of images) formats. One way to realise hierarchy is to create a relationship between abstractions, using a language feature named inheritance. Let us take the hierarchy principle, for example. It takes years of experience to understand that these are the essence of OOP (and not the favourite features that your programming language provides), and following these generic principles gives us incredible power in problem solving. With regularity, we can create uniform solutions that are easier to grasp and understand. With hierarchy, we can organise or arrange abstractions at multiple levels.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |