Active Object pattern uses an ActiveObjectEngine which holds a list of Command objects. It has two functions: one to add a new Command object and one to execute and remove the commands. The purpose is to remove the method execution from the method invocation. Since PHP doesn’t support multi-threading this example is in Java.
We’re building an Android application that has a list of movies that you can rate. When rating a movie it makes an API request to a server to store your rating. If we have the code create a new thread for each rating request it’s possible that an earlier request may be processed after a later request meaning if we rate the movie a 4 and change our minds and rate it a 3 and the API call to set it to a 4 got delayed our final rating of the movie could be 4 even though we really want a 3. If we have the code make the rating request in the UI thread we can guarantee that our rating request went through and was processed in the correct order but blocking the UI thread is a bad user experience.
The Active Object pattern is a perfect fit for this problem. It consists of an ActiveObjectEngine that holds onto a list of C