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

Assignment Help:

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;


Related Discussions:- Structure of an object type in pl/sql

Assignment2, How do I display usernames for students from a student table, ...

How do I display usernames for students from a student table, assigning each student a username initials001 (initials is the actual student initials), and if the students initials

Using delete - collection method, Using DELETE This process has three ...

Using DELETE This process has three forms. The DELETE removes all elements from the collection. DELETE(n) removes the nth element from the nested table. When n is null, then D

Fetching across commits, Fetching Across Commits The FOR UPDATE clause...

Fetching Across Commits The FOR UPDATE clauses acquire exclusive all row locks. All rows are locked when you open the cursor, and when you commit your transaction they are unl

Ensuring backward compatibility, Ensuring Backward Compatibility   The...

Ensuring Backward Compatibility   The PL/SQL Version 2 permits some abnormal behavior which Version 8 disallows. Particularly, Version 2 permits you to (i) Make the forw

Disjunction - sql, Disjunction (OR, ∨) Again we have nine rows instead...

Disjunction (OR, ∨) Again we have nine rows instead of just four and again, when unknown is not involved, the rows are as for 2VL. Also, when anything is paired with true, t

Cosmozoic theory - origin of life, COSMOZOI C THEORY - Richter (1865...

COSMOZOI C THEORY - Richter (1865) proposed the cosmozoic theory that says that life came by spores (cosmozoa) or other particles from other planets on the earth.

Grouping and ungrouping in sql, Grouping and Ungrouping in SQL Example...

Grouping and Ungrouping in SQL Example specifying EXAM_MARK in place of COURSE in the main FROM clause. Example: Obtaining C_ER2 from EXAM_MARK SELECT CourseId, CAST

Difference between ttitle and btitle, TTITLE and BTITLE are commands in Pl-...

TTITLE and BTITLE are commands in Pl-SQL to control report headings and footers. This Ttitle & Btitle are mainly used on creating SQL*PLUS report. Ttitle is used for toptitle headi

Components of an object type in pl/sql, Components of an Object Type: A...

Components of an Object Type: An object type encapsulates the operations and data. Therefore, you can declare the methods and attributes in an object type specification, but no

Library system, Hi,am developing a library system and relating all the tabl...

Hi,am developing a library system and relating all the table is somehow complex,could you kindly assist me

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd