How about you can put Delphi like properties in packages. That way you can build code in packages that mimics the getting and setting of properties like it does in Delphi code.
As you may (or may not) know, the code for creating a property in Delphi (with a getter and a setter) is as follows:
function getfoo: boolean;
procedure setfoo(const AValue: boolean);
property foo: boolean read getfoo write setfoo;
function bar.getfoo: boolean;
Result := fFoo;
procedure bar.setfoo(const AValue: boolean);
fFoo := AValue;
Note that I use a set procedure and a get function to get more control over the property to get and set the value.
Now, convert this approach to a PL/SQL Package:
The header (interface)
CREATE OR REPLACE PACKAGE bar
— Author : PBAREL
— Purpose : demonstrate properties
PROCEDURE foo(foo_in IN BOOLEAN );
FUNCTION foo RETURN BOOLEAN;
The body (implementation)
CREATE OR REPLACE PACKAGE BODY bar
PROCEDURE foo(foo_in IN BOOLEAN )
fFoo := foo_in;
FUNCTION foo RETURN BOOLEAN
This way you can address the private package variable as if you are just addressing a public package variable, but you have more control on how it behaves. In the set procedure, for instance, you can take action on how your package should behave after the ‘property’ has been set to a certain value. You can even control what is returned depending on a certain value of the private package variable.
For instance, you can create a boolean property that internally behaves as an integer value. Pass it true in the set procedure and the integer is raised by one. If you retrieve the value using the get function, the value returned will be true if the integer is greater than 0. That way you can set a flag multiple times consecutively and check the value at any time without having to worry about it’s exact value.