dimanche 10 juillet 2016

What is the correct architecture design here?

The problem is taken from initializing and retrieving data from Firebase, however I will translate this to pseudo in order those who are not familiar could also contribue. Please consider the following code: `

//Given the following API (from Firebase)
MyRemoteDBClass.asyncAuthenticate(initCompletedListener);
MyRemoteDBClass.asyncDataFetch(fetchCompletedListener)
// of course you have to authenticate before fetching the data
Class MyClassA.init()
{ 
    MyRemoteDBClass myRemoteDBClassInstance = new MyRemoteDBClass();
    myRemoteDBClassInstance.asyncAuthenticate(some_listener);
}
// Then somewhere in the app:
Class MyClassB.asyncDataFetch(MyRemoteDBClass myRemoteDBClassInstance){
    myRemoteDBClassInstance.asyncDataFetch(myClassBObject_as_listener) 
}`

The problem is that the calls of ClassA and ClassB are pretty close in timeline and I don't know if I get to call the asyncFetch before or after the init of myRemoteDBClassInstance was already completed.
How can I promise that I get to call myRemoteDBClassInstance.asyncDataFetch method in MyClassB after the init was completed?

Aucun commentaire:

Enregistrer un commentaire