I have two classes and one other object. I need to get the same object (the same instance) in these classes and ability to modify it form these classes. In first class I only need getter of this object, in second class I need setter.Both classes are in one more class(Let's call her the third one) on the basis of composition. I thinking about passing reference from third class to first and second, but during it, it will be null. If I set it to some value from class second, the reference in class first, still will be reference to null? Is it any better and proper way to do this?
class First {
SomeClass object;
public void setObject(SomeClass object) {
this.object = object;
}
public SomeClass getObject() {
return object;
}
}
class Second {
SomeClass object;
public void setObject(SomeClass object) {
this.object = object;
}
public SomeClass getObject() {
return object;
}
}
class Third {
First first;
Second second;
SomeClass object;
public void initializeClasses(){
first.setObject(object);
second.setObject(object);
}
}
But in the momment of initializeClassed the reference is null. So if I after that set in Second class it will be the same object in First class?