YOUR FEEDBACK
Two great PDF creators
Michael Jahn wrote: related to the snapscan - are their an samples of the ...
SOA World Conference
Virtualization Conference
$50 Savings Expire May 23, 2008... – Register Today!


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
POWERBUILDER LINKS YOU MUST CLICK ON


PB And Java

Digg This!

Most PowerBuilder developers are aware of object-oriented concepts like inheritance, encapsulation, and polymorphism. A lot has been said about them, and I don't want to reinvent the wheel by discussing what they are and how they're used in PB applications. The main purpose of this article is to explain one of the lesser known concepts of object-oriented programming, namely, upcasting. Later I'll give an example of method and variable overriding in conjunction with upcasting in PowerBuilder and how it differs in Java.

I came across upcasting when I was preparing for Sun certification for Java. When I learned more about it, I realized that it's something common to PowerBuilder, too. In fact, I had used it before, but I didn't know the term. I then asked a few colleagues if they knew about it: these longtime PowerBuilder developer friends had no idea what was I talking about. That's when I decided to write an article about it.

What Is Upcasting ?
Some of you may be familiar with the term casting. In many programming languages it means changing the data type. Casting can be implicit or explicit. For example, consider this code in PowerBuilder:

int li_rowcount
li_rowcount = dw_1.RowCount()

The return type of 'RowCount()' function is long. However, the above assignment is perfectly valid even though the variable 'li_rowcount' is declared 'int' (of course, there will be problems in the runtime if the 'Rowcount()' returns a value greater than the maximum 'Int' value). This is possible because of implicit casting supported by PowerBuilder

Several low- and mid-level languages support explicit casting. Once you understand casting, upcasting should be obvious if you visualize the inheritance tree below.

In this example the user object (or class) 'n_cst_son' is inherited from the user object (or class) from 'n_cst_father'.

By virtue of inheritance, 'n_cst_son' class gets all the functions (in OO terminology, called as methods) and properties of the parent class. But that's not all. Inheritance also defines a 'relation' between child class and parent class. This relation is best described by saying: 'The child class is of type ÔParent' class.'

For example, in the script of your window, the following is perfectly legal:

n_cst_father lnv_father
lnv_father = create n_cst_son

Here the object of child class is created and assigned to the object of type parent class. This is possible because of upcasting by virtue of inheritance.

Examples of Upcasting At this point some of you may be wondering why, how, and where you'd use upcasting in PowerBuilder. Well, you've already used it if you ever passed a DataStore or nonvisual user object through Message object's PowerObjectParm. As you may recall, it's a common practice in PowerBuilder to pass structures and Data-Stores through a Message object. Since all PB objects are inherited from PowerObject, any PB object can be passed.

Upcasting is indispensable if you're writing any framework or even a generic program. Consider this function, which returns the Filter string for both DataWindows and DataStores:

//parameter a_dw_or_ds PowerObject
string ls_filter

ls_filter = a_dw_or_ds.dynamic &
describe("DataWindow.Table.Filter")

// A Question mark means no filter set.
if ls_filter = '?' then
ls_filter = 'Error or NoFilter'
end if

return ls_filter

Listing 1 contains the complete code for the upcasting window.

Overriding Methods and Variables in PB and Java
In the next code we'll see overriding methods and variables in PowerBuilder in conjunction with upcasting and how it's different in Java.

I created two NVOs shown earlier: 'n_cst_son' inherited from 'n_cst_ father'. Each object has a defined one-instance variable for salary and both have a function with an identical signature that returns the age. In essence, the child class has overridden the variable salary as well as the function that returns the age.

On the command button of a window I coded the following

n_cst_father lnv_father
lnv_father = create n_cst_son

Now the question is, what would be the value of lnv.father.i_salary? Of lnv_father.uf_getage()?
Will it return the son's value or the father's value?
Note that 'lnv_father' is declared to be of type 'n_cst_father' but is assigned the reference to 'n_cst_son'.
It turns out that PowerBuilder totally forgets about the declaration of 'lnv_father' once we assign 'n_cst_- son' object to it. Thus both values returned are of 'n_cst_son' (see Figure 1 and Listing 2).

Similar code in Java reveals that Java never forgets the type of the object when looking for instance variables (see Figure 2 and Listing 3).

Summary
To simplify the job of a programmer, PowerBuilder hides many of its OO features. However, learning those concepts will always benefit the PB developer. Though Java is more object-oriented than PowerBuilder, and of course has more publicity about being object-oriented, many people seem to forget that PowerBuilder is object-oriented too, and that many of the same features existed in PowerBuilder long before Java was born.

About Atul Kane
Atul Kane, a consultant based in San Jose, California, has worked with PB since version 3.and has nine years of programming experience. He is also a Sybase-certified PowerBuilder developer associate and a certified Sun Java programmer with a degree in computer science.

PBDJ LATEST STORIES . . .
3rd International Virtualization Conference & Expo: Themes & Topics
From Application Virtualization to Xen, a round-up of the virtualization themes & topics being discussed in NYC June 23-24, 2008 by the world-class speaker faculty at the 3rd International Virtualization Conference & Expo being held by SYS-CON Events in The Roosevelt Hotel, in midtown
The PB Future: More on Graphs in PowerBuilder 11.5
Last week I posted a screen shot of the new 3D Rendering capabilities being added to some of the 3D graphs in PowerBuilder 11.5. It was met with mixed reviews on the PowerBuilder Futures newsgroup (forums.sybase.com) so I went back to the drawing board to see what I could come up with.
BluePhoenix Expands Modernization Collaboration with Microsoft
BluePhoenix announced that it has expanded its collaboration with Microsoft on legacy modernization projects. The collaboration provides customers moving their applications or databases to .NET-based environments the best in both modernization services and technical support. BluePhoeni
Sybase PowerBuilder Delivers AJAX and .NET Enhancements Enabling Rich Internet Application Development
Sybase announced that AJAX development capabilities and further Microsoft .NET enhancements have been added to the latest version of Sybase PowerBuilder 11, the premier 4GL rapid application development (RAD) tool. PowerBuilder 11.2 represents another milestone in the PowerBuilder road
PowerBuilder 11.2 Released: Sybase's Flagship IDE
Sybase has released the production version of its flagship .NET development tool - PowerBuilder version 11.2. This latest release of its premier IDE for RAD includes not only standard fixes but also a good list of new features. Here is the 'Coles Notes' version of these new features.
PowerBuilder Takes You To .NET
In June of 2007, Sybase released PowerBuilder 11. PowerBuilder developers can now deploy PowerBuilder components as .NET Assemblies or as .NET Web Services. A PowerBuilder developer can now create these .NET resources so that those who develop .NET solutions can benefit from PowerBuild
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING POWERBUILDER / SYBASE NEWS
Sybase and Sun Set Guinness World Record for World's Largest Data Warehouse
Sybase, Inc. (NYSE:SY), the largest enterprise software and services company exclusively