Welcome!

Helping Developers Master PowerBuilder Classic and .NET

Yakov Werde

Subscribe to Yakov Werde: eMailAlertsEmail Alerts
Get Yakov Werde via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Blog Post

The Case of the Indirect Ancestor Call

A solution to a possible legacy application migration issue

Many enterprise scale applications built prior to version 5 / PFC were architected based on what I'll call the Generalized Ancestor design pattern.  This pattern relies heavily on inheritance and generalized event scripts within the ancestor levels of the hierarchy.  Figure one shows a hypothetical window class hierarchy.

We all know that the default call sequence of events is Extend.  To make this happen the painter inserts a ‘hidden' Call Super :: <<event name>> line at the top of each descendent event script.  This forces control up to the ancestor code before descendent code is invoked.  If you go into the painter and uncheck Extend, this line of code is removed from the source; effectively breaking the call chain.  It's important to note that PowerScripts supports calling into ancestor class at any level of the class hierarchy using the CALL ancestorobject {`controlname}::event syntax.  See online help for the Call statement for complete details.

Framework architects try to address the majority of possible scenarios in their designs.  With generalized ancestor design, there is no elegant way to deal with exceptions to the rule.  Exceptions to the rule usually force an implementation class developer to override some ancestor scripts and either duplicate some ancestor code in descendents (eek gads, copy and paste!) or work around the some of the hierarchy by using indirect calls to get at pieces of generalized ancestor code.

Everything was fine and good until PowerScript touched .NET.  In .NET, ancestor methods can be declared virtual providing them the possibility of being overridden in descendents. Consequently, descendent methods can be declared override, polymorphically replacing their ancestor counterparts at runtime.  Most importantly however, .NET override descendents only have the ability to call their direct ancestors using the base keyword.  There is no way to directly migrate PowerScript indirect calls to .NET.  You have to refactor before you migrate to .NET.

Refactoring indirect ancestor calls is straight forward.  The refactoring catalog offers at least two ways to address the problem.  The first uses the Extract Method technique.  You packaged the block of ancestor event code in a new protected or public method (function) within the ancestor class itself; you then replace the block of code with a call to the new method.   You also replace the descendent class indirect call with a call to this new ancestor method using a direct reference.

The second technique might be appropriate if the code segment is large or there is more than one block of code to be externalized.  This refactoring uses the Extract Class technique.  In this case you'll extract the bundles of functionality into another class.  You then replace the extracted block with a call to the new method within its new class owner.  You also replace the descendent class indirect call with a call to this new ancestor method using a direct reference variable.

Case Solved!

More Stories By Yakov Werde

Yakov Werde, a 25 year IT industry veteran, is a member of TeamSybase and the newly formed Sybase Customer Evangelist Team. Yakov is a recognized author, speaker and trainer who has been designing and delivering PowerBuilder, .NET, EaServer, Web App Development, and Java training for over 14 years to corporate, military and government developers. Prior to discovering his aptitude as an educator, Yakov worked as an architect, project manager and application coder in the trenches of application software development. Yakov holds a Masters in Education with a specialty in instructional design for online learning from Capella University and a BS in math and computer science from Florida International University. Yakov, managing partner of eLearnIT LLC (www.elearnitonline.com), authors and delivers workshops and web based eLearning tutorials to guide professional developers toward PowerBuilder Classic and .NET mastery. Follow Yakov on Twitter as @eLearnPB