mardi 12 février 2019

What is the name of the anti-pattern that avoids using callbacks by using delayed function calls?

I've seen this anti-pattern in many places while maintaining some code for an Android application, and I don't know what to call it. Basically, function1 is an asynchronous function that needs to be followed by function2. Instead of putting function2 in a callback that will execute when function1 is completed, the programmer decided to first schedule a delayed call to function2 with an arbitrary time and then call function1.

void foo() {
    // delayed call to function2
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            function2();
        }
    }, 1000);

    // call function1
    function1();
}

I can only assume this was done because it's simpler and quicker than defining an interface that accepts callbacks. I just want to know if it has a name and maybe some specific documentation on how to properly handle this situation.

Aucun commentaire:

Enregistrer un commentaire