2.6. Building Flexibility Into Your Packages

Who is going to argue with this one? Sure, we want our code to be flexible, in a practical sort of way. It is quite another thing to internalize this issue in the context of packages and figure out how to take full advantage of the package structure to offer maximum flexibility.

If a program is going to be widely reusable, it should be able to adapt to different circumstances to meet different needs. It is easy to talk about flexibility. I have found that when it comes to packages there are two basic ways to be flexible when writing programs for others to use:

  1. Offer lots of parameters in the parameter lists of the package's functions and procedures. This is the traditional, well-worn path.

  2. Provide toggles or on-off switches, distinct from the main programs of the package, which modify the behavior of those programs. This approach takes advantage of the package structure to offer a new way of doing things.

It certainly makes sense to offer arguments in a packaged program unit to improve the flexibility of that individual program. Consider the display procedure of the PLVtab package, whose header is shown below:

PROCEDURE display 
    (table_in IN date_table, 
     end_row_in IN INTEGER,
     header_in IN VARCHAR2 := NULL,
     start_row_in IN INTEGER := 1,
     failure_threshold_in IN INTEGER := 0,
     increment_in IN INTEGER := +1);

This procedure has a whole bunch of parameters, and every one of them makes sense for the display of a particular table. Do you ...

Get Advanced Oracle PL/SQL Programming with Packages now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.