1. Michael Connell
  2. PowerBuilder
  3. Thursday, 9 December 2021 08:52 AM UTC

Hi,

We have inherited a legacy PowerBuilder application and in the system documentation, in a section entitled "Object Encapsulation", I have found the following when discussing object level functions and instance variables:

"Private access right is discouraged since private is only class private, not instance private."

Is this correct?

Regards,

Michael Connell.

Roland Smith Accepted Answer Pending Moderation
  1. Monday, 13 December 2021 19:24 PM UTC
  2. PowerBuilder
  3. # 1

For a variable value to be available to multiple instances of a class, it would have to be defined as a Shared Variable. Instance Variable values are only for that particular instance.

Comment
There are no comments made yet.
Arnd Schmidt Accepted Answer Pending Moderation
  1. Thursday, 9 December 2021 20:01 PM UTC
  2. PowerBuilder
  3. # 2

Hi Michael,

".. private is only class private, not instance private.".

Yes, that is (still) correct.

afair that was also discussed in this Q&A.

But I do not think that this is an argument for not using private declarations.

Remember: Only Instances of the same(!) class can call the private functions or modify the private instance variables in other instances of the class.

regards

Arnd

Comment
  1. Michael Connell
  2. Monday, 13 December 2021 10:02 AM UTC
Arnd,



Thank you for your response. I understand what you're saying: that private is only class private because instances of the same class can call the private functions or modify the private instance variables in other instances of the same class, but I'm having problems understanding how you would for example code a class to make a call from one instance of that class to a private function in another instance of the same class.



When coding the class the instances don't exist. How can I code the constructor event of a class for example to call a private function in instance B of the class from instance A of that very same class? It's this "chicken and egg" problem that I can't get my head around.



Regards,

Michael.
  1. Helpful
  1. Arnd Schmidt
  2. Monday, 13 December 2021 11:31 AM UTC
I think the whole question is more an academic point of view.

The question is how instance A can get a reference to Instance B - you mention the constructor.

You can also have a public function in your class that accepts an instance of the class as an argument.

In such a public function you can modify the private instance variables or call any private function in the instance of the argument. I do not want to discuss "readonly" here :-)

All in all it seems that these "solutions" lead to ...let's say ... bad code. Why would you write such a class? Because you can?!

But the statement about "class private" makes sense in a kind of academic way. For sure the statement is more irritating than it helps.

I found the other Q&A. Eventually the statement of your documentation was inspired by this discussion:

https://community.appeon.com/index.php/qna/q-a/when-private-access-is-not-entirely-private-bug-or-feature



regards



Arnd
  1. Helpful 1
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Thursday, 9 December 2021 14:27 PM UTC
  2. PowerBuilder
  3. # 3

Hi, Michael -

The following information may help...

From PB Help topic titled "Defining the access level / Defining user-defined functions":

 

From PB Help topic titled "Access for instance variables / Syntax of a variable declaration":

Comment
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.