1. #1 by Aaron West - July 22nd, 2010 at 18:07

    We’re using a ServiceLocator in a decent sized AIR application after reading this post. The pattern definitely helped us solve the problem of mock vs local vs staging vs production execution. Some developers simply aren’t involved in the server-side code creation, so they run the app in what we’re calling “mock” mode. This mode feeds the app with data from local XML files.

    To maximize the benefit of a ServiceLocator we’ve defined 5 different XML files that match to each run mode: mock, local-only, staging, production and current. “Current” isn’t really a run mode, but instead is what the app uses each time it fires up. Separating these run modes from the current mode has given us the flexibility to run any service in any mode. One service can be fed from mock XML data while another can be fed from the local server-side system.

    Or, we can copy all the XML from one of the files - mock.xml for instance - and paste the XML into current.xml setting all services to use mock data.

    The only downside to this method that I can see is the additional workload it puts on the developers. Whenever we introduce a new service or a new method of a service we have to write the service handler at least twice. Once to retrieve and use mock data from XML and once to retrieve and use data from the server.

    In my opinion the flexibility gained from ServiceLocators is worth the extra service programming.

(will not be published)