Best practice for refactoring functions in OO?

Rob Fitzpatrick

ProgressTalk.com Sponsor
Hi all,

I'm still new to all things OO and am looking for some guidance. I'm working on a little side project and have a working POC implemented in procedural code. Now I am trying to refactor it using classes and I'm a bit stuck on one thing. In my current code I have some helper functions that are implemented in a super procedure, with prototypes in an include for reusability. So it looks something like this:

Code:
/* library.i */
/* prototype */
function getObjectType returns character ( objectType as integer ) in super.

/* library.p */
session:add-super-procedure ( this-procedure ).
/* implementation */
function getObjectType returns character ( objectType as integer ):
  case objectType:
    when 0 then return "".
    when 1 then return "Table".
    when 2 then return "Index".
    when 3 then return "LOB".
    when 8 then return "Area".
    otherwise return "Unknown object type".
  end case.
end function.

/* frontend.p */
run library.p persistent.
{ library.i }
display getObjectType( 1 ).  // Table

So far, so good.

Now I have refactored my code into two separate classes (one for business logic and one for data caching) and I want to have access to a library of helper "functions" (which I assume should become methods in some class) from both. In other words, I have frontend.p which NEWs a.cls and b.cls and I want to be able to invoke any of a set of methods from within methods in either a or b.

I could merge a and b into a monolithic class and put the methods there as well but that feels obviously wrong. Should I put these helper methods in a c.cls that is a superclass of a and b? Or have a c.cls that is a delegate class where a and b are container classes that have method stubs for each of the methods in c? The docs suggest this might be right for me but I'm having a hard time finding usable sample code. Or should I do something else I haven't listed here?

I hope this is clear. Any help is appreciated. Thanks!
 

Bounty

New Member
Something like this:

MyLibrary.cls
Code:
CLASS MyLibrary:

  METHOD PUBLIC CHARACTER getObjectType(INPUT objectType AS INTEGER):
    ...
  END METHOD.
 
END CLASS.

FrontEnd.cls
Code:
CLASS FrontEnd INHERITS MyLibrary:

  METHOD ... VOID SomeMethod:
 
    DISPLAY getObjectType(1).
 
  END METHOD.
 
END CLASS.
 
Top