I was disappointed to learn that INSTANCE variables in an object do not override GLOBAL variables of the same name just as LOCAL variables in a function do. It seems to me that the concept of encapsulation is violated when an INSTANCE variable can be accessed from the outside by simply adding a GLOBAL declaration to it.
I was hesitant to post this observation since I'm sure it will expose my ignorance of the new PowerBasic classes and objects... but my curiosity got the best of me. I'm hoping for some reflections of others on this topic.
I was hesitant to post this observation since I'm sure it will expose my ignorance of the new PowerBasic classes and objects... but my curiosity got the best of me. I'm hoping for some reflections of others on this topic.
Code:
#DIM ALL GLOBAL counter AS LONG CLASS cTest INSTANCE counter AS LONG CLASS METHOD CREATE() 'constructor counter = 40 END METHOD INTERFACE iTest INHERIT IUNKNOWN METHOD incrCounter() INCR counter END METHOD END INTERFACE END CLASS FUNCTION PBMAIN() LOCAL oTest AS iTest LET oTest = CLASS "cTest" 'counter = 100 'this will change the object's counter oTest.incrCounter MSGBOX STR$(counter) 'access to objects's counter END FUNCTION
Comment