
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















Object-Oriented Concepts
Object-Oriented Concepts
Attributes
^ Definition^ ^
contacts
contact
person_type, c_date^
--^ object
type^ can
be^ used
like^ any
other^
built-in
data^ types.
INTO^ contacts
person_type(‘Tommy
Trojan’,
--^ instance
’24^ Jan
--^ person_type
is^ instantiated
and^ values
are^ assigned
to
--^ the^
attributes
of^ the
object
instance.
person_type(‘Scott
Tiger’,
--Built-in
constructor
method,
person_type(att1,
att2)^
is^ invoked
--to^ create
a^ new^
object^
instance
of^ person_type,
specify
values
--for^ its
attributes(name,
phone),
and^ set
the^ object
into^ a
--variable
p. INSERT^
INTO^ contacts VALUES^
(person_type(‘Scott
Tiger’,
’10^ Feb
--Same^
thing^ occurs
here.
TYPE^ person_type
name^
phone^
person_table
OF^ person_type;
INSERT INTO person_tableVALUES (person_type (‘Scott
Tiger’, ‘321-123-1234’));
SELECT VALUE(p) FROM person_table p WHERE p.name is ‘Scott Tiger’;-- Single-column table: each row is a person_type object-- Perform
object-oriented operations
CREATE TABLE person_table
(
name^
phone^
INSERT INTO person_tableVALUES (‘Tommy Trojan’, ‘213-740-1212’);SELECT name, phone
FROM person_table; -- Multi-column table: treat person_table as a relational table
AS^ OBJECT
(
x^
NUMBER, y^
NUMBER, r^
NUMBER, ORDER MEMBER FUNCTION match(c
circle_type) RETURN INTEGER );
/
CREATE OR REPLACE TYPE
BODY circle_type
AS
ORDER MEMBER FUNCTION match (c circle_type) RETURN INTEGER ISBEGINIF r < c.r THEN
-- 3.14*r
2 <^ 3.14*c.r
2
RETURN –1;
-- any negative number ELSIF r > c.r THENRETURN 1;
-- any positive number ELSERETURN 0;END IF;END;END; -- returns only one integer value among positive, 0, and negative.
OO Concepts - Inheritance
TYPE^ person_type
ssn^
name^
address
--To^ permit
subtype,
object
type^ should
be^ defined
as^ NOT
--By^ default,
an^ object
type^ is
TYPE^ student_type
person_type
deptid^
major^
TYPE^ employee_type UNDER
person_type
empid^
mgr^
TYPE^ part_time_student_type
student_type
numhours