Click or drag to resize

Inheritance

Object inheritance is very important for building a working domain. This topic describes how to implement inheritance, using the Domain library.

Implementation

To demonstrate how inheritance is implemented, lets take an example.

Suppose we have the following hierarhcy:

  • Document

  • LogisticsDocument

  • SalesOrder

We need to define the corresponging repositories:

  • DocumentsRepository

  • LogisticsDocumentsRepository

  • SalesOrdersRepository

To the user of the library, these repositories should present the illusion, that each of them is collection of all respective objects. For example, the DocumentsRepository should provide the illusion, that it is a collection of all documents, despite the fact, that each document might be stored in a different table and is a separate object class.

Then, we have to instantinate and add to a repository source one instance of each of the repositories. "Why?", would anyone ask. The reason is simple. Each repository is responsible for handling queries for its object type. If we don't add a repository instance to the repository source, it would be unable to handle queries for the respective domain object.

The DocumentsRepository and LogisticDocumentsRepository are abstract repositories. E.g. they cannot instantinate new objects, they just provide functionality for their descendants. But, they are not created as abstract classes, because of the need to create an instance from them, for handling queries.

Suppose we make a query for Document. In this case, the data source will be queried for the Documents table and it will be retrieved in the buffer. The specific instance of DocumentsRepository should be responsible for reconstructing the correct object from each row of the Documents table. Remember, that these objects are descendants of Document, but are actually different types. So, the DocumentsRepository should reliably find the right type to instantinate and call its constructor. This happens through overriding the ReconstructObject() method.

Specifically for EnterpriseOne, ReconstructObject() works by querying the DocumentTypes table and finding out the correct repository by looking at the Entity_Name column.