0% found this document useful (0 votes)
25 views10 pages

Object Types

This document discusses object types in PL/SQL. It covers declaring object types which include attributes, constructors, functions, procedures, and map/order functions. It also discusses implementing object bodies, getters and setters, inheritance and polymorphism through subclasses, and implementing object type collections. Object types define how to store data and API operations through member functions and procedures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views10 pages

Object Types

This document discusses object types in PL/SQL. It covers declaring object types which include attributes, constructors, functions, procedures, and map/order functions. It also discusses implementing object bodies, getters and setters, inheritance and polymorphism through subclasses, and implementing object type collections. Object types define how to store data and API operations through member functions and procedures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

OBJECT TYPES

CHAPTER 11

BY: JOSE LUIS MOLINA ZULUAGA


A COLLECTION OF FUNCTIONS CAN BE GROUPED
TOGETHER TO PERFORM A TASK THAT REQUIRES A
SET OF FUNCTIONS. ORGANIZED GROUPS OF
FUNCTIONS ARE MODULES, AND THE PROCESS OF
GROUPING THEM TOGETHER IS MODULARIZATION.
MODULES ARE STORED IN PL/SQL PACKAGES.
PACKAGES, LIKE FUNCTIONS AND PROCEDURES,
HIDE THEIR COMPLEXITY THROUGH A PREDEFINED
APPLICATION PROGRAMMING INTERFACE (API).
OBJECT TYPES DEFINE HOW TO STORE DATA AND
DEFINE API OPERATIONS, ALSO KNOWN AS MEMBER
FUNCTIONS OR MEMBER PROCEDURES.

Object types

Object types and objects are also known as classes in many


OOPLs.
Object Basics
The same naming requirements as Declaring Objects Types:
those used with other objects in the
database apply to objects. Object PL/SQL object types, have a prototype definition, which includes three
specialized functions—CONSTRUCTOR, MAP, and ORDER.
type names in PL/SQL must start
with an alphabetical character and * A constructor function lets you create an instance of an object.
consist of only alphabetical * The map and order functions allow you to sort objects inside
characters, numbers, or
SQL statements, or sort object instances inside a varray or table collection.
underscores.
You need to list elements in the following order: attributes, constructors,
functions, procedures, and the map or order function.
THE EDITIONABLE CLAUSE LETS YOU CREATE
CONCURRENT VERSIONS OF OBJECT TYPES. THE
ACCESSIBLE LETS YOU WHITE LIST THE CALLERS OF
THE OBJECT TYPE. ANY MEMBER OR STATIC
FUNCTION CAN RETURN A SCALAR OR COMPOSITE
DATA TYPE. THE INSTANTIABLE CLAUSE MAKES IT
POSSIBLE FOR YOU TO CREATE INSTANCES OF AN
OBJECT TYPE.

YOU CAN BUILD AN OBJECT TYPE WITH THE


FOLLOWING STATEMENT:
IMPLEMENTING OBJECT BODIES

YOU MUST PROVIDE AN IMPLEMENTATION IN THE


OBJECT BODY FOR EVERYTHING YOU HAVE IN THE
OBJECT TYPE. THE ONLY ATTRIBUTES, FUNCTIONS, AND
PROCEDURES IN OBJECT BODIES ARE THOSE DECLARED
IN THE OBJECT TYPE. THE FOLLOWING IS THE
PROTOTYPE FOR IMPLEMENTING AN OBJECT BODY:

DEFINES A HELLO THERE OBJECT TYPE THAT WHITE


LISTS ONLY A SORTER FUNCTION.

WHITE LISTING OBJECT TYPES


GETTERS AND SETTERS

GETTERS AND SETTERS ARE COMMON OOP TERMS INDICATING


THAT YOU GET OR SET A CLASS INSTANCE VARIABLE. IN PL/SQL
YOU NEED TO WRITE AN INDIVIDUAL GET_VARIABLE_NAME()
FUNCTION AND SET_VARIABLE_NAME() FUNCTION FOR EACH
CLASS ATTRIBUTE. THE IMPLEMENTATION OF THESE TWO
MEMBER METHODS IS STRAIGHTFORWARD.
INHERITANCE AND POLYMORPHISM

OBJECT-ORIENTED PROGRAMMING LANGUAGES


DEMAND A CHANGE IN THINKING. OBJECTS ARE
EXTENSIBLE BECAUSE YOU CAN ADD TO THEIR
CAPABILITIES BY BUILDING SUBCLASSES.
SUBCLASSES INHERIT THE BEHAVIORS OF OTHER
CLASSES, WHICH BECOME KNOWN AS SUPERCLASSES.
SUBCLASSES CAN ALSO OVERRIDE THE BEHAVIORS
OF THEIR SUPERCLASS BY CREATING METHODS TO
REPLACE SUPERCLASS MEMBERS.
THE IDEA THAT SUBCLASSES EXTEND AND CHANGE
BEHAVIORS OF THEIR SUPERCLASSES IS TERMED
MORPHING. POLYMORPHING IS THE PROCESS OF
MULTIPLE SUBCLASSES INHERITING THE BEHAVIORS
OF SUPERCLASSES. OBJECTS INHERIT AND
POLYMORPH BEHAVIORS BY EXTENDING BASE
BEHAVIORS IN AN ORGANIZED TREE CALLED AN
OBJECT HIERARCHY.
DECLARING SUBCLASSES

ORACLE OBJECT TYPES DEVELOP THEIR IMPLEMENTATION UNDER THE SUPERCLASS. YOU MUST STATE THAT A
MEMBER METHOD IS AN OVERRIDING BEHAVIOR BY PUTTING THE OVERRIDING KEYWORD IN FRONT OF THE
MEMBER FUNCTION OR PROCEDURE. THE MAP AND ORDER MEMBER FUNCTIONS ARE ELEMENTS OF THE FORMAL
PARAMETER LIST. THEY ARE ONLYIMPLEMENTED IN THE OBJECT TYPE. ALTERNATIVELY, YOU CAN COUPLE THE
PARENT MAP OR ORDER FUNCTION TO ALL SUBTYPES. THIS TYPE OF COUPLING REQUIRES THAT YOU MAINTAIN
BOTH WHEN CHANGING EITHER. SUBTYPES CALL THE MAP OR ORDER MEMBER FUNCTION FOR BASE OBJECT
COMPARISON AND THEN THE MEMBER FUNCTION PERFORMS A SUPPLEMENTAL SUBTYPE COMPARISON.
IMPLEMENTING SUBCLASSES
THE PROCESS OF IMPLEMENTING SUBCLASSES IS
CLOSER TO THE GENERIC PROCESS FOR
IMPLEMENTING A BASE OBJECT TYPE.
THE IMPLEMENTATION OF THE OBJECT BODY IS
SHOWN HERE:
IMPLEMENTING OBJECT TYPE COLLECTIONS
SINCE COLLECTIONS DON’T INHERIT ANY OF THE BEHAVIORS FROM THEIR BASE
ELEMENT DATA TYPE, YOU MUST WRAP A COLLECTION TYPE INSIDE ANOTHER
OBJECT TYPE IF YOU WANT TO ACCESS THOSE BEHAVIORS.

Declaring Object Type Collections


Object type collections require a base object type and a collection of the base object type. After you create those, you can build an object type
collection. This section leverages the item_object type created in the section “Static Member Methods”.

Implementing Object Type Collections


The overriding CONSTRUCTOR function takes an item_table collection as its only parameter. The local c variable provides the index value because
you can’t construct object type collections
by using the i of the for-loop. The difference between the CONSTRUCTOR function and the STATIC get_items_table function is what they return.
The CONSTRUCTOR function returns an instance of the items_object object type, which has an attribute that holds a nested collection of
item_object instances. The STATIC get_items_table function returns a collection of item_object instances.

You might also like