Sub Class_Globals
Private marrPersons(6) As clsPerson
End Sub
Public Sub Initialize
InitPersonsArray
End Sub
Private Sub InitPersonsArray
For i = 0 To 5
Dim Person As clsPerson
Person.Initialize
marrPersons(i) = Person
Next
End Sub
???post #1
Types are classes.
???post#2
"DoSomething" is not private to Person (as it's a clsPerson)
Why? It is totally ok for programming languages to have implicit design elements. In this case, a sub without an "access specifier" is public. Do you also give the default values to all your variables that you declare instead of letting the language implicitly assign those values?BTW I would at least add a warning for Subs declared without their "access specifier" (Public / Private) (actually I wouldn't even let the compiler accept it).
Dim i As Int
Dim s As String
Dim b As Boolean
Dim i As Int = 0
Dim s As String = ""
Dim b as Boolean = False
This makes perfect sense. Think about it. You are in clsPersons. In that class you can access main by Typing Main. and whatever public variable or sub there is. You can also type modUtils. and whatever public variable and method there is. Now you declare a clsPersons variable in clsPersons name Person. It makes totally sense that you can type Person.Main. whatever global variable or sub there is and Person.modUtils. whatever global variable or sub there is. You are still in the clsPerson class and in that class (while actually writing code in the class), the class and any other variables of that class (in this case Person) have access to the same modules/classes/variables and subs. I don't see anything unusual at all here[I thought I would have attached the sample project but now it seems superfluous to me, the image is enough]
Now this one is interesting. What you did leave out is that you had to explicitly write in the sub name in the CallSubDelayed/CallSub routine. The IDE did not help you autocomplete this. And yes, the code gets executed as requested. Now what? If I have a library to which I do not have the source, then the IDE would not help me resolve private subs and this would be a moot point. I would have to keep on guessing to find out what is available. And for what purpose? What is my intent in all of this? And if I have the source to the library and I see these private methods and then choose to use CallSub routines to call those private subs, what is the difference between that and me just rewriting the source of the library to give me access? The way I see it, if I willfully break encapsulation, then I have to deal with the after-effects (if any) of my decision. (Sorta like using undocumented system calls to an OS to get work done, knowing that future releases may break my code. How dare OS developers let me get a hold of those undocumented system calls)and you get the log = you can access private methods of an object if you use CallSubDelayed (or CallSub)
It would help you not to make the mistake of declaring a method as public (implicitly) when you want it to be private instead. Of course, if every private method is accessible as if it were public using CallSub... it's all useless!Why? It is totally ok for programming languages to have implicit design elements. In this case, a sub without an "access specifier" is public.
Absolutely not. You can't write code inside an object (class, of course) that accesses external elements that you don't even know if they exist.This makes perfect sense. Think about it. You are in clsPersons. In that class you can access main by Typing Main.
And? You can still accidentally name a method public even though you meant for it to be private. Mistakes can happen, even with explicitly spelling out the access specifier.It would help you not to make the mistake of declaring a method as public (implicitly) when you want it to be private instead.
No. If I'm the developer and I feel the need to access a private sub in a particular situation without declaring it public for all situations, then this is a perfectly good way of achieving this.Of course, if every private method is accessible as if it were public using CallSub... it's all useless!
But you do know that they exist! modUtils exists. clsPerson can access modUtils and any clsPerson object within clsPerson can access modUtils. There is absolutely nothing wrong with that.Absolutely not. You can't write code inside an object (class, of course) that accesses external elements that you don't even know if they exist.
You don't have to have the chance, it has to be forbidden.... if I willfully break encapsulation...
Then it is also useless that a warning appears because you declared a variable without specifying its type!And? You can still accidentally name a method public even though you meant for it to be private. Mistakes can happen, even with explicitly spelling out the access specifier.
No it does not. A language implementation can do whatever it wants to. And I actually like how B4X handles this situation. B4X is a tool to develop, not a tool to showcase some sort of pure implementation of OOP. BTW, show me a "pure" OOP language that is widely used.You don't have to have the chance, it has to be forbidden
Only if you actually use the modUtils code module in your class. If you don't use it, then you don't need to have it. Just because it is accessible while you are writing code in the class, does not mean that it is tied to the class. Why don't you write an example where you actually can produce the case you are talking about (where a class/object suddenly becomes unusable in another project because of the issues you seem to have with the language).By doing that, you could only use that object in that specific project, which has that modUtils code module.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?