Active Object

Overview

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.

The Problem

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 Solution

The Active Object pattern is a perfect fit for this problem. It consists of an ActiveObjectEngine that holds onto a list of C

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

About the Author

  • Chris LondonSenior Web ArchitectPartners In Leadership

    I've always worked as an innovative programmer. My insights and creative thinking result in superior products and customer satisfaction. Working full time as a senior web architect I've used lots of exciting technologies (i.e., Ember, Backbone, Handlebars, etc) and developed a lot of exciting sites. In my spare time I hope to develop even more exciting and new technologies. I've been programming professionally for 9 years in everything from desktop applications to web applications to mobile applications.

    Web: https://plus.google.com/116403409191372324375