Hi, it would be nice if it were possible to automatically create the "GET" and "SET" methods of the classes, like C # does, so you don't have to write or copy / paste code
I've made a more complete version of my ClassCreator (posted here). Basicly you can create your getter or setters from the variables of a class, even if they are seperated with a comma. Source code is included, feel free to do whatever you want with it.
B4X is a RAD programming language. In Java and C#, public fields are discouraged and instead you are expected to create getters and setters. This is not the case in B4X.
Start with a public field and later switch to getters and setters if you need to add more logic.
I honestly don't see the difference in a class module ?, whereas it's more obvious in a Custom View.
Could you show me with a simple example what you mean please?
' MyClass1
Process_Globals
Public Value As Int
' If Value was Zero, error.
' You could check it here, of course, but Value could be used also in many other routines.
Public Sub Divide(Num As Int) As Single
Return Num / Value
End Sub
B4X:
' MyClass2
Process_Globals
Private mValue As Int = 1
Public Sub setValue(V as Int)
If V >= 0 Then
mValue = V
Else
'...
End If
End Sub
Public Sub getValue As Int
Return mValue
End Sub
' mValue will never be zero.
Public Sub Divide(Num As Int) As Single
Return Num / mValue
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.