Android Question How to do this: abc.(xyz).(efg).(klm)?

Hanz

Active Member
I see some codes which go like this: abc.(xyz).(efg).(klm). I understand that in b4x, object oriented, in particular, inheritance is done thru encapsulation, but how can I make an object capable of doing like that?

Thanks!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1.There is no inheritance in B4X.
2. The syntax of the code you posted is wrong.
You can do:
B4X:
abc.DoSomething(xyz).AndAnotherThing(efg).

Any sub that returns a specific type of object will behave like this:
B4X:
Public Sub DoSomething(x As Int) As SomeObject

If you are trying to implement the "builder" pattern where you can chain methods that all act on the same instance, as happens with StringBuilder, CSBuilder and others:
B4X:
Public Sub Append(S As String) As StringBuilder
 ...
 Return Me
End Sub
 
Upvote 0
Top