Reusable Components [ VIRTUOSO CODE GENERATOR Reference Manual ] MPE/iX 5.0 Documentation
VIRTUOSO CODE GENERATOR Reference Manual
Reusable Components
A component is reusable if the component can be used again and again, to
perform similar logic for different business problems. These components
can be shared within a team of people developing the same application
system, or across an entire MIS organization. You have the flexibility
to decide how to share code, based on what is possible within your
organization.
Reuse Today
Software reuse is a concept that is not new. Through the use of
subroutines, copy libraries and include files it has been possible to
share code. These approaches, however, have been problematic. Although
subroutines are good for primitive functions, their interfaces are often
cumbersome. Subroutines, copy libraries and include files all suffer
from the same basic problem; they cannot be adapted to solve a particular
problem. When using these methods, you will find it is difficult to
reuse the code that was developed in the past, because the code does not
quite match the specific problem you are trying to solve. Modifying the
code will cause problems, since you will impact all users of this common
code. When code must be used "as-is", it is often easier to "reinvent
the wheel" and start from scatch.
Another type of reuse is the "copy and change" method. Here you are
faced with solving a problem that is similar to one you have solved in
the past, and so you find the program that you wrote, copy the source
code, and modify the code as required. This method allows you to get the
application done without significant effort; however, the drawback is
that now you must maintain two copies of essentially the same logic. As
you solve more and more application problems with this method, your
maintenance burden grows very large.
Reuse with Virtuoso
With Virtuoso you reuse the same basic components, but you have the
ability to adapt the component to the particular problem that you are
solving. Virtuoso provides the flexibility to allow you to customize the
component to solve your specific business problem. No longer are you
forced to reuse code "as-is."
Virtuoso automates this construction process for you, giving you the
productivity needed to create the application quickly. Virtuoso also
allows you to maintain a single copy of the basic logic even though it
may have been used to create many different programs. With this approach
you have one copy of the logic required to perform the task, and all that
you specify is the data that is different for the specific problem that
you are solving. This approach simplifies your maintenance since you no
longer maintain multiple copies of the same basic logic.
Using a Reusable Component. When you use a reusable component, you adapt
that component to the problem that you are solving. A reusable component
can be adapted to solve a particular problem by specifying the data names
to be included with the component and/or the custom logic to be used.
The ways in which a component can be adapted are shown in Figure 1-1
Figure 1-1. Reusable Software
The component contains the logic that can be used over and over to solve
different business problems. For example, the code that would be used to
open a TurboIMAGE database could also be used in an inventory
application, an accounting application and so forth. Another example is
the logic that is used to display a FORMSPEC form, allow a user to enter
a key value, and then retrieve the data from a master dataset
corresponding to that value. This logic could be used in many types of
applications.
The aspects of a component that can be customized are:
* Data Names: The specific data names on which the reusable code is to
operate. For example, if the reusable component contained the logic
to open a TurboIMAGE database, the data for the component would be
the name of the database to be opened by the reusable logic. In the
case of an inventory application, this would be the name of the
inventory database. If the reusable component displays a FORMSPEC
form, the data would include the name of the FORMSPEC form to be
displayed.
* Custom Logic: Logic to perform operations which are not performed by
the component and are specific to the problem being solved. Often,
the custom logic handles the processing of specific data. For
example, the logic that edits a particular screen field would be
considered custom logic. In the case of an order processing
application, custom logic might be the processing required to
validate an order number.
Solving Different Problems with the Same Component. Reusable logic can
be used to solve different business problems. It is the data and the
custom code that makes the logic specific to the problem being solved.
The Virtuoso Code Generator can transform a reusable component into
application logic by combining the reusable logic with data about the
specific business problem as well as any custom code that is required.
By combining data names that describe different business problems with
the reusable logic, different application logic will be produced. Simply
varying the data will result in different application logic. This
concept is illustrated in Figure 1-2:
Figure 1-2. Reusable Logic and Data
The same is true for custom code. By combining reusable logic with
different custom code, different application logic will result.
Reusable Logic. The logic can be separated from the data that is to be
processed by the logic by referring to symbolic names called keywords
rather than the actual data names within the code. A keyword contains
the specific data value that is to be incorporated in the generated
logic. For example, the reusable logic may perform operations on a
database. The specific database is not indicated in the logic; rather,
the reusable logic operates on the user-specified keyword image-database.
The keywords are given values at generation time. These values are then
substituted into the reusable logic to produce application logic. The
process of substituting values for the keywords is known as parameter
replacement.
Figure 1-3 illustrates some typical keywords that you might find in
reusable logic and their values:
Figure 1-3. Data in an Application
The reusable logic contains references to keywords. To indicate that a
keyword is to be replaced by its value in the generated logic, you
precede the keyword with the "!" character. The generator performs
parameter replacement as it generates the output text.
The example shown in Figure 1-4 illustrates some logic which refers to
several keywords. The logic is coded with these keywords rather than
specific data names. Since the logic does not reference specific data
names, the same logic can be reused to solve similar programming
problems. The example in Figure 1-4 illustrates reusable logic for
adding records to a TurboIMAGE dataset. When this type of problem arises
in any programming context, this reusable logic can be used to solve the
problem. All that you need to do is to specify the data that is unique
for the problem.
In the first COBOL statement, the value of the keyword image-dataset will
be replaced with the value of the keyword at generation time. The same
is true for the third statement; when the generator processes the line,
the value of the keyword dblist will be replaced in the generated text.
Figure 1-4. Reusable Logic
The logic and the data names are combined to produce the application
logic intended to solve your business problem. The reusable logic is
combined with the data that is specific to the problem that is being
solved. The Virtuoso Code Generator produces the application logic by
looking at each source line and replacing each keyword reference by its
value.
The example below illustrates reusable logic that consists of three COBOL
statements. Each statement refers to a keyword preceded by the
substitution character. In the first statement, Virtuoso will replace
the keyword ELEMENT by its value "Product-Number". In the second
statement the keyword IMAGE-DATASET is replaced by its value
PRODUCT-MAST. In the final statement the keyword IMAGE-DATABASE will be
replaced with its value "PRODDB".
Figure 1-5. Combining Data and Logic
The concept of reuse is not specific to COBOL. The Virtuoso Code
Generator provides a framework that allows you to reuse code and
documentation. It is possible to remove the data and specific text from
documentation to allow it to be reused.
Reusable Component Libraries
The Virtuoso Code Generator supports two types of reusable components.
The first component type is a reusable function or macro. A macro is a
name that represents the logic for a particular function that is to be
performed. For example, a macro could be used to generate code that
opens a TurboIMAGE database or displays a FORMSPEC form on a terminal.
The second type of reusable component is a reusable structure or model.
A model represents the logic for an entire program or subprogram. For
example, a model could generate the logic to display a FORMSPEC form,
read the data entered by the user, and then add the data to a TurboIMAGE
dataset.
Both models and macros allow you to standardize the code that is
generated by Virtuoso. The coding standards for your organization can be
incorporated into the reusable components and thereby automatically
enforced. Any requirements that are specific to your environment can
also be built into the components that are used by your organization.
For example, if you have a security mechanism that is used to open all
TurboIMAGE databases, this could easily be incorporated into the macro
that opens databases.
Reuse applies to more than source code; documentation often has a
standard format that is to be used by all individuals in an organization.
With Virtuoso this standard format can be represented as a model. Just
as with source code, the model would represent the "structure" of the
documentation to be generated. The model would contain the standard
sections and define the organization and content of the documentation
produced.
MPE/iX 5.0 Documentation