Business Rules Class and Object

The Data Handler object instantiates a Business Rules object from a Business Rules class with predefined methods in which you can place application-level code to enforce business rules related to maintaining an application's data.

Tip: Data-Level & Application-Level Business Rules Code: The VPME Data Builder’s record-level code and field-level code give you places to code data-level business rules for specific tables, views, CursorAdapters and fields. The VPME Business Rules class methods gives you a place to code application-level business rules that aren’t tied to specific tables, views, CursorAdapters and fields.

The Business Rules class is a custom, or non-visual, Visual FoxPro class. It contains methods that are called when data handling processes occur within an application.

 For example, when a record is saved through a form:

·       The form’s Save method is run, which runs:

·       The Data Handler object’s SaveRecord method, which runs various methods, including:

·       The PreSave method of the Business Rules object,

·       The record-level PreSave code you enter into the Data Builder, and

·       The FieldValidation_RecordLevel method of the Data Handler object, which runs the FieldValidation method of the Data Handler object, which runs:

·       The Field Validation-related methods of the Business Rules object, and

·       The Field Validation-related code you enter into the Data Builder.

As you can see from this example, VPME gives you two places to enter data-related business rules code that will be applied during data handling processes:

·       Data Builder Data-Level Code: In the Data Builder you can enter record-level code (see Record-Level Data-Driven Developer Code) and field-level code (see Field-Level Data-Driven Developer Code) to define business rules for specific tables, views, CursorAdapters and fields. When methods of the VPME Data Handler are run, your Data Builder data-level code is run at the appropriate places.

·       Business Rules Class Application-Level Code: In the Business Rules class methods you can enter code to define data-related business rules that are not unique to specific tables, views, CursorAdapters and fields. When methods of the VPME Data Handler are run, your Business Rules class application-level code is run at the appropriate places.

Tip: Although we say above that the code you enter into Business Rules class methods is not unique to specific tables, views, CursorAdapters or fields, that is not necessarily always true. While generally code that is unique to specific tables, views CursorAdapters and fields should be entered into the Data Builder, there’s nothing stopping you from putting such code into a method of the Business Rules class – particularly, if you find a good reason for doing so.

 

Business Rules Class

The Business Rules class is named “VPMDataHandlerBusinessRules”, and is located in the VPMDataHandlerBusinessRules.VCX class library. The DEVDataHandlerBusinessRules.VCX and PRODataHandlerBusinessRules.VCX class libraries contain subclasses of the VPMDataHandlerBusinessRules class. However, all of the Business Rules class code is in the methods of the VPMDataHandlerBusinessRules class.

Business Rules Object Instantiation

In a VPM Enterprise application the Business Rules object is instantiated by the Data Handler object each time the Data Handler object is instantiated, which is at application startup and at the instantiation of forms. After the Business Rules object has been instantiated, its properties and methods can be referenced or called using the _SCREEN.oApp.oVPMDataHandler.oBusinessRules or <form object reference>.oVPMDataHandler.oBusinessRules object references.

The Business Rules object is instantiated from a class that is specified in the cBusinessRulesClass and cBusinessRulesClass_ClassLibrary properties of the Data Handler object. By default, these two properties both contain “PRODataHandlerBusinessRules”.

Tip – Major Benefit: The importance of the way the Business Rules Object is instantiated is that the code you add to the methods of the Business Rules class can use the data handling functionality of the oVPMDataHandler object and also can access any data open in the data session of the object that instantiated the oVPMDataHandler object (i.e., the form or application object).

More:

Business Rules Class Methods