Encapsulation of operations, methods & persistence
The document discusses encapsulation in programming, emphasizing its role in binding data and functions while hiding implementation details from external users. It explains the application of encapsulation in database objects, highlighting operations for creating and deleting objects, and the distinction between visible and hidden attributes. Additionally, it covers the concept of persistence in object-oriented programming, differentiating between transient and persistent objects, and introduces mechanisms for achieving persistence through naming and reachability.
Encapsulation
Encapsulation is relatedto the concepts of abstract data types and information
hiding in programming languages.
Encapsulation is a mechanism of binding data with functions.
3.
Encapsulation of Operations
Theconcepts of encapsulation is applied to database objects in ODBs by
defining the behavior of a type of object based on the operations that can be
externally applied to objects of that type.
Some operations may be used to create (insert) or destroy (delete)
The external users of the object are only made aware of the interface of the
operations, which defines the name and arguments (parameters) of each
operation.
The implementation is hidden from the external users.
4.
Encapsulation of Operations
Fordatabase applications, the requirement that all objects be completely
encapsulated is too stringent.
One way to relax this requirement is to divide the structure of an object into
visible and hidden attributes (instance variables).
Visible attributes can be seen by and are directly accessible to the database
users and programmers via the query language.
The hidden attributes of an object are completely encapsulated and can be
accessed only through predefined operations.
Most ODMSs employ high-level query languages for accessing visible
attributes.
6.
Persistence
The OOPL isused to specify the method (operation) implementations as well as
other application code.
Not all objects are meant to be stored permanently in the database.
Transient objects exist in the executing program and disappear once the
program terminates.
Persistent objects are stored in the database and persist after program
termination.
The typical mechanisms for making an object persistent are naming and
reachability.
7.
Persistence
The naming mechanisminvolves giving an object a unique persistent name
within a particular database.
This persistence object name can be given via a specific statement or operation
in the program
The named persistent objects are used as entry points to the database through
which users and applications can start their database access.
It is not practical to give name to all object in large database in thousands of
objects so, some objects are made persistence using second mechanism called
reachability.
8.
Persistence : Reachability
Thereachability mechanism works by making the object reachable from some
other persistent object.
An object B is said to be reachable from an object A if a sequence of references
in the database lead from object A to object B.
If we first create a named persistent object N, whose state is a set (or possibly a
bag) of objects of some class C, we can make objects of C persistent by adding
them to the set, thus making them reachable from N.
Hence, N is a named object that defines a persistent collection of objects of
class C. In the object model standard, N is called the extent of C.