Android Question Ask for best practice in OOP

antonomase

Active Member
Licensed User
Longtime User
Hi,

There is very long time that I used classes and objects.

I have two objects : the second one uses the first one
B4X:
Class Object1
Sub Class_Globals
end sub

Sub OneSub as Boolean
 ...
end sub

Class Object2
Sub Class_Globals
  Private obj1 as Object1
end sub

Sub SetObject1 (o as Object1)
  obj1 = o
end sub

Sub AnotherSub
  If obj1.OneSub then ...
end sub


Main code 
dim obj1 as Object1
dim obj2 as Object2
obj1.Initialize
obj2.Initialize
obj2.SetObject1(obj1)
obj2.AnotherSub

But now, obj1 must also call a method from obj2.
If I create a private instance variable obj2 in Object1, it will be something recursive : obj1 is an instance variable of obj2 which contains an instance variable obj1, ...

What will the best practice to resolve this ? Object1 and Object2 are two objects very different, but very interdependant ?

Thanks
 
Top