Comments on: Design Patterns in PL/SQL – The Template Pattern https://technology.amis.nl/2006/03/10/design-patterns-in-plsql-the-template-pattern/ Friends of Oracle and Java Thu, 21 May 2015 20:49:51 +0000 hourly 1 http://wordpress.org/?v=4.2.2 By: Zlatko Sirotic https://technology.amis.nl/2006/03/10/design-patterns-in-plsql-the-template-pattern/#comment-2967 Fri, 18 Jan 2008 22:16:42 +0000 http://technology.amis.nl/blog/?p=1089#comment-2967 The formatting of my code example is lost. Link for formatted example:
“The Template Design Pattern in PL/SQL”
http://www.quest-pipelines.com/pipelines/plsql/tips06.htm#OCTOBER

I agree that the curent object types in Oracle aren’t practical for transient objects, first because we need references between transient objects.
But, I think that Oracle object types are OK for persistent objects – for “column objects”, not for “row objects”:
“OR(DBMS) or R(DBMS), That is the Question”
http://www.quest-pipelines.com/pipelines/plsql/tips.htm#OCTOBER

C.J.Date in “An introduction to Database Systems” (2004, page 885) says:
“… object/relational systems … are, or should be, basically just relational systems that support the relational domain concept (i.e., types) properly
– in other words, true relational systems, meaning in particular systems that allow users to define their own types.”

Best regards,
Zlatko

]]>
By: Koray Dakan https://technology.amis.nl/2006/03/10/design-patterns-in-plsql-the-template-pattern/#comment-2966 Fri, 11 Jan 2008 11:44:48 +0000 http://technology.amis.nl/blog/?p=1089#comment-2966 5) And most important, you cannot have private members, meaning, you cannot add members (method or variable) to the type body that don’t exist in the type spec, so all members are publicly accessible . And this ruins the whole concept of encapsulation principle. Packages have both public spec and private implementation, why not object have it only God knows..

]]>
By: Koray https://technology.amis.nl/2006/03/10/design-patterns-in-plsql-the-template-pattern/#comment-2965 Fri, 11 Jan 2008 11:10:01 +0000 http://technology.amis.nl/blog/?p=1089#comment-2965 I don’t find the curent objects types in Oracle practical, because:
1) When you want to change a supertype, you get an error that says you have to drop the subtypes first.. This is not a practical solution cause first you have to generate the scripts for all subtypes (and all their subtypes in the type hierarchy, then do your work on the super type and regenerate all the sub type tree in the correct order, and then change the sub types if necessary (which means the process continues recursively).. It could be done with an automated script, but why does Oracle want this I don’t understand.
2) Also, if some of the subtypes are abstract (not instantiable) then it’s quite possible a Forms application to give “time signature changed” errors, as it does on package specs..
3) As in the example Zlatko Sirotic gives, you have to use a dummy member variable in order to create interfaces or abstract classes.. By the way, I didn’t think of doing this so I shyed away from using objects types, but now I see I can create interfaces with a dummy variable:)

]]>
By: Serp Land https://technology.amis.nl/2006/03/10/design-patterns-in-plsql-the-template-pattern/#comment-2964 Mon, 18 Jun 2007 16:08:16 +0000 http://technology.amis.nl/blog/?p=1089#comment-2964 Hi together
I think this Template Pattern can be implementet a very clean way with object types. I tried with a simple pseudo object and it really works!
First I thought ever not using object types. Why should I?
Now I got it – I can almost implement every desing pattern the clean way with object types. So I think every pl/sql developer should start using it.
At the moment I’m looking forward to use the Template Pattern in our production environment 😉

]]>
By: Zlatko Sirotic https://technology.amis.nl/2006/03/10/design-patterns-in-plsql-the-template-pattern/#comment-2963 Tue, 14 Mar 2006 16:53:33 +0000 http://technology.amis.nl/blog/?p=1089#comment-2963 Dear Lucas,

My opinion is that PL/SQL classes (object types) still aren’t finished.
Database 9i has made a giant leap forward compared to 8i (inheritance, polymorphism …),
but in 10g there is hardly anything new.
In my opinion it is a priority to add references between transient objects and then,
perhaps, even a garbage collector.

Between the way, I sent my PL/SQL “wish list” to Steven Feuerstein’s site “21st Century PL/SQL”
http://www.oracleplsqlprogramming.com/IC/ideas/data_structures_and_datatypes/object_types/index.php
(Add advanced O-O features like those found in Eiffel)
and
to the AskTom site: Thanks for the question regarding “What don’t you like about Oracle?”
http://asktom.oracle.com/pls/ask/f?p=4950:8:4407442689342146348::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:48704116042682
(My wishes – new features of Oracle Database 11br).

In addition, I present you my two texts in witch I’m pointing out some of PL/SQL object oriented characteristics:
Calling the Parent Object’s Version of an Overridden Method
http://www.quest-pipelines.com/pipelines/plsql/tips03.htm#JUNE
and
Dynamic Method Dispatch and Method Overloading in a Subtype
http://www.quest-pipelines.com/newsletter-v4/0503_C.htm

But, adding more OO capabilities to PL/SQL is the second thing in my wish list.
The first thing is – better support for business rules in the database.
We need “What Not How: The Business Rules Approach to Application Development” (book by C.J.Date).
My motto is: “Thou shall not do in the Middle Tier, what thou could have done in the Data Tier”
(Toon Koppelaars in “A first JDeveloper project: Choices made, lessons learned”, Oracle World 2002).

If the database would support business rules, then this two complex examples would be futile:
Solving “COMMIT business rules” on the Database Server
http://www.oracle.com/technology/oramag/code/tips2002/032402.html
and
Avoid a “Vicious Cycle”
http://www.oracle.com/technology/oramag/code/tips2003/081003.html

Best regards,

Zlatko Sirotic

]]>
By: Lucas Jellema https://technology.amis.nl/2006/03/10/design-patterns-in-plsql-the-template-pattern/#comment-2962 Sat, 11 Mar 2006 07:47:46 +0000 http://technology.amis.nl/blog/?p=1089#comment-2962 Dear Zlatko,

Thanks a lot for this very interesting example! Most of us tend to shy away from using the Oracle Object Extensions – certainly in part because of ignorance – so having your demonstration is valuable to a lot of us, including myself.

Are you making use of the Object Extensions and the OO facilities available for Object Types a great deal?

best regards,

Lucas

]]>
By: Zlatko Sirotic https://technology.amis.nl/2006/03/10/design-patterns-in-plsql-the-template-pattern/#comment-2961 Fri, 10 Mar 2006 14:53:21 +0000 http://technology.amis.nl/blog/?p=1089#comment-2961 We can try to use PL/SQL 9i/10g object types.

But then in PL/SQL 9i/10g we must use MEMBER (non-STATIC) methods (procedures/functions):

CREATE OR REPLACE TYPE templ_method_abstract AS OBJECT (
dummy VARCHAR2(10),
MEMBER PROCEDURE template_method,
NOT INSTANTIABLE MEMBER PROCEDURE operation1,
NOT INSTANTIABLE MEMBER PROCEDURE operation2
)
NOT FINAL
NOT INSTANTIABLE
/
CREATE OR REPLACE TYPE BODY templ_method_abstract IS
MEMBER PROCEDURE template_method IS
BEGIN
operation1;
operation2;
END;
END;
/

CREATE OR REPLACE TYPE templ_method_concrete_a UNDER templ_method_abstract (
OVERRIDING MEMBER PROCEDURE operation1,
OVERRIDING MEMBER PROCEDURE operation2
)
/
CREATE OR REPLACE TYPE BODY templ_method_concrete_a IS
OVERRIDING MEMBER PROCEDURE operation1 IS
BEGIN
DBMS_OUTPUT.PUT_LINE (‘Operation 1 in class CONCRETE A’);
END;

OVERRIDING MEMBER PROCEDURE operation2 IS
BEGIN
DBMS_OUTPUT.PUT_LINE (‘Operation 2 in class CONCRETE A’);
END;
END;
/

CREATE OR REPLACE TYPE templ_method_concrete_b UNDER templ_method_abstract (
OVERRIDING MEMBER PROCEDURE operation1,
OVERRIDING MEMBER PROCEDURE operation2
)
/
CREATE OR REPLACE TYPE BODY templ_method_concrete_b IS
OVERRIDING MEMBER PROCEDURE operation1 IS
BEGIN
DBMS_OUTPUT.PUT_LINE (‘Operation 1 in class CONCRETE B’);
END;

OVERRIDING MEMBER PROCEDURE operation2 IS
BEGIN
DBMS_OUTPUT.PUT_LINE (‘Operation 2 in class CONCRETE B’);
END;
END;
/

DECLARE
l_templ_method_object templ_method_abstract;
BEGIN
l_templ_method_object := NEW templ_method_concrete_a (‘DUMMY’);
l_templ_method_object.template_method;

l_templ_method_object := NEW templ_method_concrete_b (‘DUMMY’);
l_templ_method_object.template_method;
END;
/

Why we can’t use STATIC methods?
First, in PL/SQL 9i/10g STATIC method can’t bee abstract (NOT INSTANTIABLE):

CREATE OR REPLACE TYPE template_method_abstract_2 AS OBJECT (
dummy NUMBER(1),
STATIC PROCEDURE template_method,
NOT INSTANTIABLE STATIC PROCEDURE operation1,
NOT INSTANTIABLE STATIC PROCEDURE operation2
)
NOT FINAL
NOT INSTANTIABLE
/

LINE/COL ERROR
——– —————————————————————–
4/38 PLS-00169: modifier ‘STATIC’ conflicts with prior ‘NOT
INSTANTIABLE’ specification

5/38 PLS-00169: modifier ‘STATIC’ conflicts with prior ‘NOT
INSTANTIABLE’ specification

Second, we can try to use non-abstract STATIC methods in (abstract) parent:

CREATE OR REPLACE TYPE template_method_abstract_3 AS OBJECT (
dummy NUMBER(1),
STATIC PROCEDURE template_method,
STATIC PROCEDURE operation1,
STATIC PROCEDURE operation2
)
NOT FINAL
NOT INSTANTIABLE
/
CREATE OR REPLACE TYPE BODY template_method_abstract_3 IS
STATIC PROCEDURE template_method IS
BEGIN
operation1;
operation2;
END;

STATIC PROCEDURE operation1 IS
BEGIN
NULL; — simulates abstract method
END;

STATIC PROCEDURE operation2 IS
BEGIN
NULL; — simulates abstract method
END;
END;
/

but, (in PL/SQL 9i/10g) we can’t override STATIC method:

CREATE OR REPLACE TYPE template_method_concrete_3 UNDER template_method_abstract_3 (
OVERRIDING STATIC PROCEDURE operation1,
OVERRIDING STATIC PROCEDURE operation2
)
/
LINE/COL ERROR
——– —————————————————————–
2/32 PLS-00169: modifier ‘STATIC’ conflicts with prior ‘OVERRIDING’
specification

3/32 PLS-00169: modifier ‘STATIC’ conflicts with prior ‘OVERRIDING’
specification

Regards,
Zlatko Sirotic

]]>
By: amihay gonen https://technology.amis.nl/2006/03/10/design-patterns-in-plsql-the-template-pattern/#comment-2960 Fri, 10 Mar 2006 10:04:25 +0000 http://technology.amis.nl/blog/?p=1089#comment-2960 I’ve impelement this using oracle types, which provide abstract methods and others OO t
types.

I think it worth to show those design patterns also using oracle types

]]>