cancel
Showing results for 
Search instead for 
Did you mean: 

Polymorphism/Overloading in PB

larrypeters
Explorer
0 Kudos

In a PB12.5 pfc-enabled application I have an object function with code as follows:

    public function integer of_connect(ref transaction mytr)

    mytr = create n_tr

    mytr.dbms = profilestring('my.ini', 'Switches', 'DBMS', 'ODBC')

    mytr.dbparm = profilestring('my.ini', 'Switches', 'Dbparm', '')

    connect using mytr;

    return mytr.sqlcode

   

This function is called from many places.

Sometimes case 1:

    integer            li_ret

    transaction        ltr

   

    li_ret = of_connect(ltr)

Sometimes case 2:

    integer            li_ret

    n_tr                ltr

   

    li_ret = of_connect(ltr)

Both seem to work.

Is this usage legal?

Or should I change all case 1 calls to declare ltr as 'n_tr' instead of 'transaction'

and of_connect() argument as 'n_tr'? The trouble is it is a large app and there are

maybe a thousand instances of case 1.

Could someone point me at documentation which discusses this issue or educate me in

the pros and cons of this usage?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Larry,

It's totally legal, since n_tr inherits from transaction.

In both case, a n_tr object is instantiated.

The only difference is that in case 1 you won't be able to call specific functions of n_tr, if you need it then you just have to change the declaration.

Regards

Guillaume

larrypeters
Explorer
0 Kudos

Thanks Guillaume,

Answers (2)

Answers (2)

larrypeters
Explorer
0 Kudos

I am reasonably satisfied that the usage is legal especially since it seems to work.

However, it does look suspect.

Is there an argument which demonstrates it's legality for the benefit of possible sceptics in my organization?

TIA

Former Member
0 Kudos

Hi Larry;

1) As Guillaume has already correctly pointed out this your method implementation is 100% OK.   

FWIW:

2) Your implementation example has nothing to do with OverLoading.

3) Your implementation example has nothing to do with Polymorphism. Of which, there are two types:

  - Inclusional

  - Operational

  Ahhhh ... for the good old days of teaching the  "BOOA" Course!  

Regard ... Chris

Former Member
0 Kudos

Hi Larry,

Both cases are legal, as pointed out by Guillaume and Chris. However, in a PFC-enabled application you should be using n_tr (or any objects inherited from n_tr).

Besides, you don't seem to be leveraging the power of PFC because you are creating your own functions (of_connect) instead of using the functionality already built on the PFC objects.

Regards,

Manuel

larrypeters
Explorer
0 Kudos

Thanks Chris,

I suspected that my issue is neither polymorphism nor overloading. I was looking for a description of the issue and that was the closest I got. Any suggestions as to how I should have described the issue?

larrypeters
Explorer
0 Kudos

Thanks Manuel,

The app is full of legacy code and was converted at some time from standard to pfc. I need to minimise changes and hence my question.