While experimenting with the new Module feature, which I quite like, I've stumble upon an issue that defeats the Module main purpose which is, from my understanding, encapsulation.
This, in the context of 'Classes' creation (with Interface/Structure/DataSection/..).
Lets say I have this 'Class' in a module:
Code: Select all
DeclareModule CObject
Interface Instance
RefInc.i ()
RefDec.i ()
EndInterface
EndDeclareModule
Module CObject
Structure Instance_t
*vtable
rfc.l
EndStructure
EndModule
Now let say I want to create another 'Class' which inherits from the CObject 'Class'.
Code: Select all
DeclareModule CDerived
Interface Instance Extends CObject::Instance
Plop.i ()
EndInterface
Declare.i New()
EndDeclareModule
Module CDerived
Structure Instance_t Extends CObject::Instance_t
myplop.i
EndStructure
Procedure.i New()
EndProcedure
EndModule
; The intended use:
Define *d.CDerived::Instance = CDerived::New()
The Module section is considered as a 'private' section where data cannot be seen outside of this Module section.
The drawback of this is that for inheritance to work, we have to declare the CObject::Instance_t structure into the CObject 'DeclareModule' instead of the CObject 'Module' section. But doing this, the CObject::Instance_t becomes public and everyone can access it, which defeat the encapsulation concept brought by the Module feature.
To solve this issue I'm thinking about allowing code inside private Module sections to access any other private Module sections data.
It wouldn't be 100% encapsulation of course, but at least code inside private 'Module' sections would be seen only from other private 'Module' sections, not from main code or anywhere else.
Or perhaps there is another way ?
Cheers,
Guy.