Inheritance without Polymorphy

Normally inheritance is considered tightly coupled with polymorphy. This is just fine from the view of object oriented programming languages. But in conjunction with object relational mapping polymorphy is an expensive feature. Because of that NDO makes a subtle distinction between polymorphic and non-polymorphic inheritance.

What should the latter actually be used for? In most cases non-polymorphic inheritance is used if we have to map tables with a lot of columns or tables with columns containing big BLOBs (binary large objects). Inheritance allows mapping parts of these columns to different classes.

In our example we got a table where bitmaps are stored together with header data. Let’s assume you want to write a user interface with a grid, listing the header data. Now you do not want to load the pictures from all data rows, just because you need to list the header data.

Here is a possible solution that uses inheritance without polymorphy:

    • Write a class PictureHeader.
    • Derive the class Picture from PictureHeader. Picture contains the field that can hold the picture.
    • Map Picture and PictureHeader to the same table.
    • Load several PictureHeader objects to fill the grid
    • If a picture is selected, load the picture object using the ObjectId of the PictureHeader object.

The sample does not really belong to the problem domain of travel expense accounting. This will not deter us from coding it in the same project.