Structure of an object type in pl/sql, PL-SQL Programming

Structure of an Object Type:

Similar to package, an object type has 2 parts: the specification and the body. The specification is the interface to your applications; it declares a data structure (that is, a set of attributes) along with the operations required to operate the data. The body fully explains the methods, and therefore implements the specification.

1290_Structure of an Object Type.png

Figure: Object Type Structure

All the information a client program require to use the methods is in the specification. Imagine of the specification as an operational interface and of the body as the black box. You can debug, replace, or enhance the body without changing the enhance -and without affecting the client programs.

In an object type specification, all the attributes should be declared before any methods. The subprograms only have a fundamental implementation. As a result, if an object type specification declares only the attributes, the object type body is needless. You cannot declare attributes into the body. All the declaration in the object type specification is public.

To recognize the structure enhanced study the illustration below, in which an object type for the complex numbers is explained. For now, it is adequate to know that the complex number has two sections, a real part & an imaginary part, and that quite a few arithmetic operations are defined for complex numbers.

CREATE TYPE Complex AS OBJECT (

rpart REAL, -- attribute

ipart REAL,

MEMBER FUNCTION plus (x Complex) RETURN Complex, -- method

MEMBER FUNCTION less (x Complex) RETURN Complex,

MEMBER FUNCTION times (x Complex) RETURN Complex,

MEMBER FUNCTION divby (x Complex) RETURN Complex

);

CREATE TYPE BODY Complex AS

MEMBER FUNCTION plus (x Complex) RETURN Complex IS

BEGIN

RETURN Complex(rpart + x.rpart, ipart + x.ipart);

END plus;

MEMBER FUNCTION less (x Complex) RETURN Complex IS

BEGIN

RETURN Complex(rpart - x.rpart, ipart - x.ipart);

END less;

MEMBER FUNCTION times (x Complex) RETURN Complex IS

BEGIN

RETURN Complex(rpart * x.rpart - ipart * x.ipart,

rpart * x.ipart + ipart * x.rpart);

END times;

MEMBER FUNCTION divby (x Complex) RETURN Complex IS

z REAL := x.rpart**2 + x.ipart**2;

BEGIN

RETURN Complex((rpart * x.rpart + ipart * x.ipart) / z,

(ipart * x.rpart - rpart * x.ipart) / z);

END divby;

END;

Posted Date: 10/6/2012 7:59:44 AM | Location : United States







Related Discussions:- Structure of an object type in pl/sql, Assignment Help, Ask Question on Structure of an object type in pl/sql, Get Answer, Expert's Help, Structure of an object type in pl/sql Discussions

Write discussion on Structure of an object type in pl/sql
Your posts are moderated
Related Questions
Project Description: I want to rebuild it and add better content to it It will include up to 5 forms The data will be saved on SQL server and the data access layer could b

Positional and Named Notation You can write the actual parameters when calling a subprogram, using either positional or named notation. That is, you can point to the relationsh

THEO R Y OF CATASTROPHISM OR CATALYSM (CUVIER 1769-1832) - The world has passed thorugh several stages and at the end of each stage there was a catastrophe killing all the

COMMIT Statement The COMMIT statement explicitly makes everlasting changes to the database during the present transaction. The Changes made to the database are not considered e

Autonomous versus Nested Transactions Though an autonomous transaction is started by the other transaction, it is not a nested transaction for the reasons shown below: (i)

Procedures The procedure is a subprogram which can take parameters and be invoked. Normally, you can use a procedure to perform an action. The procedure has 2 sections: the spe

Processing Transactions This part describes how to do the transaction processing. You learn the fundamental techniques that safeguard the consistency of your database, involvin

I would like to have a custom MS Access database designed and coded that would help me schedule my customer's orders and that would help me track my employees production output and

Recursion versus Iteration Dissimilar the iteration, recursion is not crucial to PL/SQL programming. Any problem which can be solved using recursion can be solving using the it

PITS Depressions in secondary cell wall is called pit. A pit present on the free cell wall surface without its partner is called Blind pit. It consists of 2 parts -