1. Benjamin Gaesslein
  2. PowerBuilder
  3. Friday, 29 January 2021 14:07 PM UTC

Let's say you have a nonvisual, non-autoinstantiated custom object called n_object, which has a private member variable long il_private.

Now let's say there's a scenario where a function of n_object needs to create another instance of type n_object, possibly using a dynamically generated name of an object inherited from n_object itself. Like:

n_object lnv_inherited

lnv_inherited = create using of_getnameofinheritedobject()

It is now possible to directly assign a value to il_private of the freshly created instance:

//compiles without errors and works at runtime
lnv_inherited.il_private = 5

Private functions are accessible as well. I'm not sure wether or not this is "bad" per se but it's certainly not the behavior I would've expected. Any thoughts?

 

Accepted Answer
Andrew Barnes Accepted Answer Pending Moderation
  1. Monday, 1 February 2021 22:13 PM UTC
  2. PowerBuilder
  3. # Permalink

Benjamin,

If I am understanding what you are saying, PowerBuilder is working as expected, and so far as I know, as PowerBuilder has always functioned. My take is that you are accessing the n_object's private il_private variable from within a n_object script.

If my reading is correct, that is the correct behavior.  In OOP, one n_object instance should be able to access the private variables of another n_object instance.  However, the private variables of n_object should be private when any other class attempts to access them.  (In C++ another one class can make another a friend to have that capability, but so far as I know PowerBuilder does not have friend classes).

Andy 

 

 

 

Comment
  1. Benjamin Gaesslein
  2. Tuesday, 2 February 2021 14:37 PM UTC
I guess that's just the way it works. I've simply never seen it before. I just learned that it works the same way in Java and probably other languages.

Well, you never stop learning.
  1. Helpful
  1. Andrew Barnes
  2. Tuesday, 2 February 2021 16:13 PM UTC
I am glad I could help.



Really the idea with private variables and functions is not so much run-time data protection but rather with compile time coding protection. By allowing a private variable to be accessed only from within the scope of the class in which it has been declared, its use is limited to whatever programmer is working on the class in question. So if you write the n_object class, you know how it functions, how its inner workings function, and can be trusted to use the il_private variable correctly in a way that some other programmer who simply uses the n_object class and may not really understand the use of il_private cannot. And if you ever need to change n_object and il_private, maybe change it to a double datatype, because it is private, you know that the only source code that needs to be considered is that of n_object.
  1. Helpful
There are no comments made yet.
Armeen Mazda @Appeon Accepted Answer Pending Moderation
  1. Friday, 29 January 2021 16:18 PM UTC
  2. PowerBuilder
  3. # 1

Hi Benjamin,

Please open a support ticket and our product engineers will analyze whether this is a bug or how PowerBuilder was designed.  In case it is not a product bug, we still need to properly document this.

Best regards,
Armeen

Comment
  1. Benjamin Gaesslein
  2. Monday, 1 February 2021 11:22 AM UTC
I have done so.
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Friday, 29 January 2021 16:25 PM UTC
  2. PowerBuilder
  3. # 2

I like your way of thinking, but personally, I would say it should be allowed as it's the same private object that has created an instance of itself.

It would like "a mother who gave birth to a son and named him Bill, but is not allowed to know his name afterwards if he has changed it during his lifetime".

regards.

Comment
  1. Benjamin Gaesslein
  2. Monday, 1 February 2021 11:43 AM UTC
I'd be hard-pressed to find a real downside to this phenomenon but it might in some cases facilitate sloppiness when it comes to encapsulation. Then again PB already does that by setting new functions and variables to public by default, so... I don't know. :)
  1. Helpful
  1. Miguel Leeuwe
  2. Monday, 1 February 2021 11:47 AM UTC
True
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 29 January 2021 20:03 PM UTC
  2. PowerBuilder
  3. # 3

Hi Ben;

  If it's designed and coded properly ... No Way!

Been that way since PB 2.0. The compiler will not allow it. Same for methods!

Regards ... Chris

Comment
  1. Chris Pollach @Appeon
  2. Monday, 1 February 2021 14:08 PM UTC
Hi Miguel;

Technically, OO in PB started in 2.0 and was mainly completed in 4.0. So yes, somewhere along that time line. ;-)

Regards ... Chris
  1. Helpful
  1. Chris Pollach @Appeon
  2. Monday, 1 February 2021 14:13 PM UTC
Hi Arndt;

FWIW: Note that its the PB Compiler that decides on the use of Private, Protected or Public at compile time - not at run time. From the compiler's P.O.V.. though both the "lnv_object pointer and the "n_object " object are the *same class* and thus, you would not get a compile error. So IMHO, this is not a PB issue / bug.

Regards ... Chris
  1. Helpful
  1. Miguel Leeuwe
  2. Monday, 1 February 2021 14:30 PM UTC
Hi Chris,

Could be that your right, but even so, I would have sworn the possibility of declaring an instance variable as private, protected or global came a few versions after 2.0.

Not really important though.

regards
  1. Helpful
There are no comments made yet.
Benjamin Gaesslein Accepted Answer Pending Moderation
  1. Monday, 1 February 2021 11:30 AM UTC
  2. PowerBuilder
  3. # 4

I've played around with this a little more and came up with this:

forward
global type n_baseobject from nonvisualobject
end type
end forward

global type n_baseobject from nonvisualobject
end type
global n_baseobject n_baseobject

type variables
private:
	long il_private
end variables

forward prototypes
public subroutine of_test ()
private subroutine of_manipulate (n_baseobject anv_external, long al_value)
private subroutine of_private (long al_value)
end prototypes

public subroutine of_test ();//
// testing local access
//
n_baseobject lnv_base
lnv_base = create n_baseobject

//compiles
lnv_base.il_private = 4
lnv_base.of_private( 5 )

//let's go crazy 
lnv_base.of_manipulate( this, 667 )

end subroutine

private subroutine of_manipulate (n_baseobject anv_external, long al_value);//
// external
//
anv_external.il_private = al_value
end subroutine

private subroutine of_private (long al_value);//
// private subroutine
//
il_private = al_value
end subroutine

on n_baseobject.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_baseobject.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

Note the line

lnv_base.of_manipulate( this, 667 )

in particular, which calls a private subroutine of a locally created instance of n_baseobject, which in turn changes the private instance variable il_private of the calling instance of n_baseobject that was given as an argument to the method.

Still not sure if this is "bad" per se but it certainly feels utterly wrong to be able to do this, as contrived as this example may be. laughing

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 1 February 2021 15:34 PM UTC
  2. PowerBuilder
  3. # 5

Yep, Private and protected variables weren't introduced until PB 5.x as it seems here:

http://www.softwarefoundry.com/publications/1997_WP_PowerScript.pdf

Just search on the word 'private' in the pdf file.

EDIT: since I actually don't seem to have a life with this Covid running around, I went to the extent to find myself an old pb 3 version somewhere and install it on a VM XP... Turns out I'm old, stubborn and very wrong: PB3 already had the protect and private stuff in it. (I can sleep now LOL).

:s

 

Comment
  1. Miguel Leeuwe
  2. Tuesday, 2 February 2021 15:56 PM UTC
LOL :)
  1. Helpful
  1. Benjamin Gaesslein
  2. Wednesday, 3 February 2021 07:50 AM UTC
It's always interesting to learn some "ancient" PB history. I started with PB9.
  1. Helpful
  1. Miguel Leeuwe
  2. Wednesday, 3 February 2021 08:10 AM UTC
Aah, you were lucky! PB3 was great, PB4 was horrible and initial versions of PB5 not too good either, PB6.5.1 was great and after that we got the new IDE interface with "lots of little windows". It took me some time to get used to that. They have their advantages, but it really took time before getting back to the development speed of 6.5.1 where you would just cntrl+tab through all the painters, use ctrl+1 or 2, 3 for expanding event and function lists, etc. (that worked perfectly in those days and it kinda still does, but seems less straightforward because of all the little windows where your focus might be on some tabbed properties window, so I've stopped doing that).
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.