borland Packages  Class Hierarchy  jbcl.dataset Package  Index 

DataModule interface

borland.jbcl.dataset.DataModule

About the DataModule interface

The DataModule is an interface that you implement when creating your custom data module class. Data modules (often referred to as data models) are specialized containers where data access components and their associated properties are collected into a reusable component. You define your data module once, then use it among various applications, or various frames within a single application.

The data module also provides a centralized location where "business logic" can be stored. "Business logic" describes the rules by which data is manipulated before and after the user (or client) sees the data. Business logic may include default values, filter criterion, constraints on data insertions, and so on. By encapsulating such logic in a single location, you are assured that every application that uses your data module provides consistent business logic.

The DataModule interface does not contain any variables, properties, methods, or events, however, by implementing this interface, you implicitly declare that your class is a data module.

You can create a custom data module class manually, or through the Data Module wizard (accessible from the File|New menu option). Either way, you implement the DataModule interface. If you use the JBuilder Data Module wizard to create your data module, it automatically creates code that instantiates your data components at the data module class level. In addition, property settings made in the Inspector are reflected in a jbinit() method. Individual "getter" methods are also created that return each Database, DataSet, DataStore (and so on) in your data module.

You are not required to use the Data Module wizard to create your data module. However, if you structure your custom data module in this manner, the JBuilder design tools can present the data components in your data module as possible choices when designing your application.

The Data Module wizard also automatically checks for different classes sharing a common name across packages in your project and prepends the package name to the class name in such cases. This prevents ambiguity between the classes that would otherwise generate a compile error.

To reference your data module in your current application, select the Use DataModule option from the Wizards menu. The dialog that appears:

When referencing your data module in your application, you can access a single instance of your data module shared across your application instead of allocating memory for multiple instances. To do this, your custom data module class should define a public static method that retrieves the current instantiation of the data module. This same method should also create and return a new instantiation if one doesn't already exist. For an example of this code, use the Data Module wizard to create a data module and examine the logic of the code it generates.

Tip: When working with DataModules, you must compile your DataModule class before it can be referenced in your project.

For more information on using a data module, see Encapsulating your data model for reuse in the Database Application Developer's Guide. For an example of an application that uses a complex DataModule, see the IntlDemo.jpr project in the samples\borland\samples\intl directory of your JBuilder installation.