Welcome!

PowerBuilder Authors: Chris Pollach, Yeshim Deniz, Jayaram Krishnaswamy, Kevin Benedict, Avi Rosenthal

Related Topics: PowerBuilder

PowerBuilder: Article

PowerBuilder Foundation Classes

Getting started

PowerBuilder includes a powerful set of foundation classes to speed development. These classes are collectively known as the PowerBuilder Foundation Classes, or PFC. Part 1 of this article provides an introduction to PFC and shows how to use it. For the experienced PFC developer, I'll outline the more recent changes and additions to PFC in Part 2.

This article is not intended as a complete professional reference for PFC - that could be (and is) the subject of an entire book on its own. Nor is it intended as a tutorial, although there are code samples to show you how to use some of the features. What you'll find here is an overview of the architecture, objects, and services of PFC so that you can envision how to use PFC to make your applications more rich, powerful, and user-friendly.

Getting Started with the PFC

What Is PFC?
PFC is a class library of precoded objects and behavior. PFC provides a head start to application developers as an "out-of-the-box" class library solution.

PFC contains no prebuilt templates. It's a set of base classes that can be extended to provide a more powerful or specialized set of classes. It is a true "foundation" library. Sybase designed PFC with the intention that it would be extended, even though many developers find the provided functionality of the PFC to be ample.

PFC is based on service-based architecture (SBA) and uses simple function calls to enable services. The result is a foundation class library with a great deal of functionality, flexibility, and reusability. It's worth noting, however, that the implementation of PFC uses layers of inheritance that tie many of the objects and references together and prevent individual objects and services from being used without including the majority of PFC objects in your application.

PFC provides basic windows, menus, and user objects. There are also additional user objects that provide services for the developer to use to enhance the functionality of any PFC application.

PFC is more than just the code; it's a complete package. As shipped with PowerBuilder 9, PFC includes:

  • PFC Classes
  • PFC Help
  • PFC Sample Database
  • Example program (located in the pfcexamples folder)
  • PFC Start Wizard
  • Tutorial
  • Utilities: Library Extender, PFC Message Manager

What Is SBA?

PFC uses service-based architecture (SBA), which is a way of building relatively lightweight objects that delegate a great deal of functionality to service objects. Windows and user objects create instances of these nonvisual service objects and request functionality and processing from them. This maximizes the developer's ability to reuse and extend the service objects without needing to modify existing objects and without having to carry around the overhead of fat ancestor objects. See Figure 1 for how objects and services relate to each other.

The traditional inheritance-based model of object construction utilized the capability of object-oriented (OO) languages to extend a base object's functionality by successively adding code in the descendants. This was an improvement over the older "copy-book"- based reuse model of non-OO languages, but there were some significant drawbacks. As the inheritance tree grew and different objects with slightly different capabilities sprouted, it became increasingly difficult to change behaviors, since where to put the new behavior in the inheritance tree was a critical question. In addition, the sheer size of the objects gave rise to the term "fat ancestor." A fat ancestor always carries along the overhead of all of its underlying code whether it needs it or not. It loads slowly and (especially in the 16-bit environment of the time) can cause the compiler to fail if it was too fat. Also, the developer was forced to choose an object out of the hierarchy to fit whatever specialized use was required. If the developer wanted to change the use of the object, it was necessary to replace it with another object from the hierarchy, and painstakingly recode all of his changes.

SBA allows you to do more with less. The ancestor simply carries "hooks" that allow it to make use of functionality contained in smaller, more efficient "service" objects. The service objects can be selectively enabled so that only those services that are actually needed are instantiated. This reduces load time and memory usage. "Object Choice" syndrome is eliminated - the developer uses a single base object and instantiates services as needed to provide desired functionality.

PFC's implementation of SBA uses instance variables in the PFC objects to provide references to service classes. The service classes are instantiated by calling a function, of_set, that creates an instance of the service and points the reference variable to the instance. The general format for the naming of these reference variables is inv_ where is an "English" name or shortcut for the service. For example, the instance variable declared in pfc_u_dw for the linkage service is named inv_linkage. To instantiate the linkage service on a u_dw control placed on a window, you would write the following statement in the window open event:

dw_1.of_setLinkage(TRUE)

Placing the code for the linkage service in the window open event ensures that all objects on the window have been fully instantiated. In cases other than the linkage service (which depends on multiple objects being fully instantiated) you would place the code to create a service in the client object's constructor or open event.

PFC Architecture

PFC is built as a set of visual and nonvisual objects with a layered design. PFC is based on two layers: the PFC and the PFE. Every object in the PFC layer has a descendant in the PFE layer. The PFC layer is where the actual code that implements PFC functionality is placed. The PFE layer is left empty for the developer to modify and extend as necessary. Objects in the PFE layer are named (for example, n_cst_dwsrv_linkage). Objects in the PFC layer are named pfc_ (for example, pfc_n_cst_dwsrv_linkage). Figure 2 shows the PFC inheritance structure for a typical object, n_cst_ wnsrv_statusbar, the window status bar service. The PFC inheritance chain includes a "pfc_"-prefixed object and a non-prefixed object for every step from the base object (pfc_n_base) to the statusbar service (n_cst_wnsrv_statusbar).

There are a few rules that go with PFC's layered design:

  • Never modify the PFC objects. Let me repeat, never modify the PFC objects! If you do this, you're simply creating migraine headaches for yourself and anyone unlucky enough to inherit your application. Keep all of your modifications in the PFE layer objects.

  • Inherit from PFE-layer objects, not PFC-layer objects.

  • Instantiate PFE-layer objects, not PFC-layer objects.

These rules allow the PFC-layer objects to be replaced as newer versions and bug fixes are released without (for the most part) necessitating the recoding of the developer's modifications and extensions. Note that over time, especially at the transition between version 5 and version 6, the PFC modifications were extensive enough that some action on the part of the developer was required to properly migrate applications to the new versions. There have also been some changes to both the underlying operating system and the PowerBuilder compiler that have caused behavior changes in the underlying objects, once again requiring minor changes to existing developer code. But these slight hiccups have been relatively few, and the PFC-layered architecture has proven to be quite stable as newer versions have been released.

PFC is divided into 10 PBLs:

  • pfcapsrv: PFC-layer application services

  • pfcdwsrv: PFC-layer DataWindow services

  • pfcmain: PFC-layer main objects and controls

  • pfcwnsrv: PFC-layer window services

  • pfcutil: PFC-layer utility and global objects and services

  • pfeapsrv: PFE-layer application services

  • pfedwsrv: PFE-layer DataWindow services

  • pfemain: PFE-layer main objects and controls

  • pfewnsrv: PFE-layer window services

  • pfeutil: PFE-layer utility and global objects and services

More Stories By Millard F. Brown

Millard F. Brown is vice president of Power3, LLC, a company providing consulting and training services for the enterprise. He has beend developing PowerBuilder applications since PowerBuilder 2 and is the co-author of two new PowerBuilder 9 books: PowerBuilder 9: Advanced Client/Server Development and PowerBuilder 9: Internet and Distributed Application Development.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.