First page Back Continue Last page Graphics

Coding Validation in a Domain


Notes:

Domains: Example

When you create a domain object, you are essentially creating a new data type; the example creates the type called URLDomain. You can then change an entity attribute’s type to your new type; in this example, you could change the type of an entity’s attribute to URLDomain. When the entity is instantiated, or when the entity’s attribute is populated or changed, the URLDomain() constructor is called. The constructor executes the validation code that you have written to verify that this attribute is valid.

Because String is a base JDK type, a domain based on a String aggregates a private mData String member field to hold the value that the domain represents.

Note: Domain validation code is executed whenever you query existing data. If existing data fails the check, you need to either correct the existing data or code the check so that existing data is determined to be valid.