An object-oriented database must provide support
for all data types not just the built in data types such as character,
integer, and float. To understand abstract data types lets take two steps back
by taking off the abstract and then the data from abstract data type. We now
have a type, a type would be defined as a collection of a type values. A simple
example of this is the Integer type, it consists of values 0, 1, 2, 3, etc. If
we add the word data back in we would define data type as a type and the set of
operations that will manipulate the type. If we expand off our integer example,
a data type would be an integer variable, an integer variable is a member of the
integer data type. Addition, subtraction, and multiplication are examples of
operations that can be performed on the integer data type.
If we now add the word abstract back in we can
define an abstract data type (ADT) as a data type, that is a type and the set of
operations that will manipulate the type. The set of operations are only
defined by their inputs and outputs. The ADT does not specify how the data type
will be implemented, all of the ADT's details are hidden from the user of the
ADT. This process of hiding the details is called encapsulation. If we extend
the example for the integer data type to an abstract data type, the operations
might be delete an integer, add an integer, print an integer, and check to see
if a certain integer exists. Notice that we do not care how the operation will
be done but simply how do invoke the operation.
Let's start by looking at traditional
programming languages and the data types that they use. Traditional languages
are based on text and numerical data types, and you are limited to what kinds of
data types that the programming language will support. Variables that are used
by the programming language have to be defined using one of the supported data
types. OT has done away with the restrictions of just using these built in data
types and allows you to create different data types. Once these new data types
are defined they are treated the same way as built in data types. The ability to
create new data types when needed and then use these data types is called data
abstraction, and the new data types are called abstract data types (ADTs).
An abstract data type is more than a set of
values. When used to create an object, it can also have method attached to it,
and the details of these methods are hidden from the user. Data abstraction
and ADT's are a cornerstone for OT because they can be created as needed, and
this helps you to think of and design computer systems to more accurately
reflect the way data types are represented in the real world.
One of the main reasons why hierarchical,
network and relational databases are being replaced is their failure to support
ADT's. These traditional databases have very strict rules foe the layout of
data and simply are not flexible enough to handle ADT's.
Encapsulation
Encapsulation gathers the data and methods of
an object and puts them into a package, creating a well defined boundary
around the object. Encapsulation is often referred to as
information
hiding,
and encapsulation can be used to
restrict which users and what operations can be performed against the data
inside the object.
Classes provide encapsulation or information
hiding by access control. A class will grant or deny access to its objects
using the public and private
access specifiers. Public members
define an interface between a class and the users of that class. Public
members can be accessed by any function in a program. Objects can contain
both public and private variables, the
public
variables are used with the objects methods or interfaces.
Private
variables are only known to the object, and cannot be accessed by an
interface. For example a private method might be used to compute an internal
value.
Encapsulation can be used in non-database
object-oriented applications to guarantee that all operations are done via the
methods that the programmer has defined in the class definition, insuring that
data can not be changed outside of its own pre-defined methods. However,
declarative database languages such as SQL allows what might be called
?declarative" retrieval and updates of data, and does not follow the rules of
encapsulation. This is called an impedance mismatch, and is inconsistent with
object-oriented database management.
As an example, in a relational database we could
define a behavior called ADD_ORDER which will check to see if there is enough
product in inventory for the order. The order object will not be created if
there was not enough product in inventory. This behavior will make sure that no
order is placed for product that is unavailable. However in a relational
database, you could use SQL and bypass this validity check and thereby add an
invalid order into the database.