Object and Code Reusability

Reusability is the facility to use existing objects and code to create new applications.

For object reusability, use Copy / Paste properties; property classes; object groups; subclassing and copying for certain objects, property classes, object Groups, and object libraries across form modules; and template forms as a base for new forms.

For code reusability, use copying of triggers and program units across modules, and create form libraries or reference triggers across form modules. Also, the triggers attached to property classes, triggers and program units (from Forms 5.x onwards) in object groups, triggers and program units in object libraries, and the code reused from template forms contribute to code reusability.

Subclassing

Subclassing is the act of making an object inherit the properties of a base object, including code. You achieve it in five ways:

In Figure 6.2, you noticed a red arrow on the left side of each button item. This is because, when a property class is applied to an object, it (the object) is subclassed.

Subclassing has the following characteristics:

Subclassing and Copying

You can copy or subclass across modules stored in a database or file system. When you subclass objects, the properties of the subclassed objects can be modified in the target module. This is an enhanced feature over referencing (available in Forms 4.5), in which only certain properties of the referenced objects can be modified in the target module ”for example,

Object Groups

Object groups enable you to reuse sets of functionally related objects by subclassing or copying the set as a whole. Again, consider the standard toolbar application. To construct such a toolbar, the following Forms objects can be used:

These three Forms objects can be grouped together to form an object group, as shown in Figure 6.3.

Figure 6.3. An example of an object group.

This object group can in turn be subclassed or copied across multiple forms where such a toolbar is required.

Here are some things to keep in mind:

Object Libraries and Subclassing by Means of Smart Classes

In the section under subclassing, I discuss five ways of subclassing. Of these, the most intelligent way is smart-classing. Smart classes are part of object libraries.

An object library is similar to a Forms library in that it is sharable across forms. The only thing extra here is, an object library can contain both Forms objects and code. Creating an object library involves the following steps:

  1. Create a module of type Object Library by double-clicking the Object Libraries node in the Object Navigator.
  2. Add objects to it by dragging them from the Object Navigator and dropping them into the object library.
  3. Mark them as smart classes. This is done by selecting the Object option in the menu and clicking on the Smart Classes suboption under it. The resulting smart class can be reused by a different object of the same type, in the same form or a different form. To do this, select the target object, right-click on it, and choose the corresponding smart class object under the Smart Classes node under it.

The object group OBJECT_TOOLBAR created in the preceding section can be added to an object library and marked as a smart class. Figure 6.4 shows how this is done.

Figure 6.4. An example of an object library and smart classing objects in it.

Marking individual objects in an object library as smart classes is not mandatory, but doing so creates a higher level of subclassing.

There is some difference between subclassing by means of a smart class and the other subclassing methods . The primary difference is that the first is the most intelligent way. The following tips suggest why smart classes are smart, and explain other related points:

Tip

Only those smart classes corresponding to the given object type are displayed in the Smart Classes list when applying a smart class to an existing object, whereas any object that makes sense for the given object can be its subclass. For example, when applying a smart class for a block object, a Property Class Smart Class is not shown in the list, even though applying a property class to a block makes sense, whereas the same property class can be made subclass for the block without using the smart class. This overrides the extra smartness of smart classes.

 

Form Libraries

Form libraries enable sharing of common code. Here are some tips for using form libraries:

Категории