Wish Auto Create Getters and Setters

unitybyte

Member
Licensed User
In Delphi and Lazarus ide, I am used to being able to right click on a private variable in a Class, and have the IDE auto generate a get and set method for the selected variable. Is that possible in B4J or can it be implemented?

This saves a lot of time when coding big classes.

Regards
Ronny
 

unitybyte

Member
Licensed User
Why? I thought that was the way to do oop and classes?

Like this:
B4X:
Sub Class_Globals
   Private mAccount_number As String
   Private mAddress1 As String
End Sub

Sub setAccount_number(value As String)
   mAccount_number = value
End Sub

Sub getAccount_number As String
   Return mAccount_number
End Sub

Sub setAddress1(value As String)
   mAddress1 = value
End Sub

Sub getAddress1 As String
   Return mAddress1
End Sub

This is how I have learned to do this things, is there an other way i B4J ?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Getters and setters do not make your code more "oop".
Generally speaking you should prefer immutable classes, so no setters at all.

Stub getters and setters are useful when you build a library. They allow you to change the implementation without breaking existing compiled code (source code will not be affected).
In other cases you can start with simple public variables and later convert them to properties when you want to add logic. It will look and behave exactly the same.
 
Top