Using a Domain to Create Custom-Validated Data Types
When you find yourself repeating the same sanity-checking validations on the values of similar attributes across multiple entity objects, you can save yourself time and effort by creating your own data types that encapsulate this validation.
For example, in your application you may have numerous entity object attributes that store strings that represent URLs. One technique you could use to ensure that end users always enter a valid URL is to create your own data type, for example URLDomain, that represents the structure and format of a URL. You can then use URLDomain as the data type of every attribute in your application that represents a URL.
When you create a new domain object, JDeveloper generates code in the domain’s constructor to call the validate() method of the domain class. When you add your validation code to this method, it is automatically executed when the domain object is instantiated.
The clear benefit of using a domain is that a domain can be used by multiple attributes whereas a validation rule (other than a global rule) applies to one attribute or entity object only.
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.