Previous Table of Contents Next


Code and data can be enclosed together into a “black box,” and these “boxes” may then function totally independent of all other objects within the system. (See Figure 2.10.) From a programming perspective, an object is an encapsulated routine of data and behaviors. Objects may contain “public” variables, which are used to handle the interfaces to the object, and “private” variables, which are known only to the object. Once created, an object is treated as a variable of its own type. For example, an object of class CAR is created as a routine with a data type called CAR, and is treated as a compound variable by the program.


Figure 2.10  An example of encapsulation.

Encapsulation is used in nondatabase object-oriented applications to ensure that all operations are performed through the programmer-defined interface, and that data will never be modified outside of the application shell. But what about ad hoc query and update? It appears that any declarative database language such as SQL that allows “external” retrieval and update does not follow the dictates of encapsulation, and is therefore inconsistent with object-oriented database management.

For example, a relational database could be defined to have a behavior called add_line_item, which serves to check inventory levels for an item, and add an item to an order only if sufficient stock is available. This behavior ensures that orders are not entered for out-of-stock items. However, with a language such as SQL, the object-oriented behavior could be bypassed, and line_item records could be added without any regard for inventory levels.

Because encapsulation and SQL are clearly incompatible, the only conclusion that can be reached is that encapsulation may be violated in Oracle8 by using ad hoc tools such as SQL*Plus.

Extensibility

Extensibility is the ability of the Oracle8 engine to add new behaviors to an existing application without affecting the existing application shell. This is an especially powerful concept and will allow Oracle8 to extend existing classes, guaranteeing that no unintended side effects from the introduction of a new object class will occur.

For example, consider a company that provides payroll services for businesses in many states. Some payroll computations are global (for example Gross_pay = hours_worked * payrate), while others are specific to a municipality or state. Using Oracle8, an existing object class definition can be extended, such that the new object behaves exactly like its superclass definition, with whatever exceptions are specified. For example, if New York City instituted a new payroll rule for New York City residents, then the general definition for New York payroll customers could be extended with a new class definition for New York City payroll customers. The only method that would be attached to this class definition would be the code that is specific to New York City; all other methods would be inherited from the existing superclasses.

The “ISA” Construct

Oracle is planning to introduce an extension to its Designer/2000 product to allow for the modeling of class hierarchies. This new extension, tentatively dubbed Designer/2001, should allow for object-oriented constructs to be described and modeled.

Here is a vision of how it might work. After establishing a class hierarchy with the Entity/Relation model, the principle of generalization is used to identify the class hierarchy and the level of abstraction associated with each class. Generalization implies a successive refinement of the class, allowing the superclasses of objects to inherit the data attributes and behaviors that apply to the lower levels of the class. Generalization establishes “taxonomy hierarchies,” organizing the classes according to their characteristics—usually in increasing levels of detail. Generalization begins at a very general level and proceeds to a specific level, with each sublevel having its own unique data attributes and behaviors.

The ISA relationship is used to create a hierarchy within the object class, and all of the lower-level classes will inherit the behaviors. The ISA relationship is used to model the hierarchy that is created as the class entity is decomposed into its logical subcomponents. Customers may be preferred_customers or new_customers, and orders may be cod_orders or prepaid_orders—each with their own data items and behaviors.

SQL For Object-Orientation

The object-oriented approach borrows heavily from the C++ and Smalltalk languages. Both of these languages allow for the storing of behaviors with the data, such that data and business rules also share a common repository.

With the properties of encapsulation, abstraction, and polymorphism, object technology systems are moving toward a unified data model that models the real world far more effectively than previous modeling techniques. Furthermore, a properly designed object-oriented model promises to be maintenance-free, because all changes to data attributes and behaviors become a database task—not a programming task.

Let’s take a look at a human analogy to the object-oriented approach. It is very natural for humans to recognize objects, and to associate objects with their classes. It is also a very natural concept to associate an object with its expected behaviors.

Even as very young children, we learned to associate behaviors with certain characteristics of objects. For example, it is not uncommon to visit the zoo and hear a three-year-old call all four-legged animals “doggies.” The child has learned to associate an object class (dog) with a data attribute (four legs). Later a child will refine his/her object-oriented paradigm, associating other data attributes with animal objects. A child also learns to associate behaviors (such as playing, having fun, feeling pain) with different visual and auditory stimuli. Many young children learn to associate unpleasant sensations (pain) with a visit to the man who wears a white lab coat (the doctor). McDonald’s corporation has spent millions of dollars exploiting this principle (much to the consternation of many parents), associating pleasant behavior with objects such as golden arches, Happy Meals, and Ronald McDonald.


Previous Table of Contents Next