(special thanks to Richard Scoop)
What do Object Persistence Framework (OPF) and its brother Model-View-Presenter (MVP) have in common, other than being object oriented patterns? Both use the same source of data. At one end the OPF reads information from a persistence mechanism (eg a RDBMS) and at the other end the MVP presents the information that the user sees from it. The link between these two is what a few authors call a Value Type Framework, which I call Data Type Framework or simply the Subject Framework.
Data Type is a set of classes that are used to store information in an object oriented way. It’s a mechanism that allow objects to be in memory, whose timeframe starts at the database being retrieved (or when it is created by the user) and finish when it is discarded by the user. The implementation of a flexible and productive Data Type Framework is one of the most complex parts in the construction of an object oriented SDK.
It’s the Data Type’s responsibility to provide a mechanism to construct business classes, such as TOrder and TClient, these classes are used to create an instance of an order or a client in memory. It’s with the Data Type that the definition of the business models, relationships between the classes, the business rules and user entered values are validated.
A Data Type, being object oriented, allows the simple creation of models with hierarchical classes, a very difficult job when a relational model is used.
Examples of how this approach helps in the construction of business rules:
One of the systems of Laserpress, a budget generator for the graphical industry, has a business object TExpense the has four subclasses: TExpenseDirect, TExpenseIndirect, TExpenseMonthly and TExpensePercentual. An expense has to be one of these four classes, when doing the actual budget calculation the system refers to the expense abstractly without knowing which of the classes it is using. Every expense class does its calculation very differently than the rest.
This same system allows the generation of a budget with four different type of items: simple, printed, blocked and book. Every budget can have items of different type, each of the four items can have different attributes, they are treated with different forms and calculated differently. The user doesn’t need to fill up a form used to store information of a book, when he just needs to register a template ( a rubber-stamp).
The construction of a model that uses a Data Type framework is initially more work intensive . The programmer needs to have a good understanding of how the SDK is used, its necessary to send more information to the model than when the relational method is used. On the other hand, all information sent to the framework is reused.Examples: the OPF uses the class model to build a script that creates the tables, primary index and foreign key constraints for the database. The MVP uses the class model to understand the details of the business classes and with this create functionality for the visual controls, such as insert or edit an item in a grid.
A lot of object oriented systems use relational database, instead of an object oriented database, to store their business objects. To make this possible, another framework is necessary to map the object-relational, in other words transform the data from the objects to the relational form and back. But this is a subject for another post.