Q: Working with both adobe flex web and desktop application I need to develop an application using flex. The requirement is to develop both a web app and a desktop application. I need to use a database for this application. I learned that there is a local database which can be used for air application.
I do not want to end up writing two applications, hence would like to reuse as much code as possible.
So, here is my plan for this:


*

*make a library project.

*write a httpservice like class for interacting with local db in air.

*a middle layer which takes care of calling the correct service (httpservice or the custom service).

*UI which interacts only with the above said middle layer for data.


Can anyone suggest if this is feasible or can share their previous experience or have any other idea?

A: Your approach is correct. You will need to create an abstraction of the services you want the application to talk to and then provide 2 different implementations: 1 for the web app, which might use remoting via AMF, webservices or http services and 1 for the desktop app, which will have a SQLite implementation.
This approach is basically an implementation of the strategy pattern, which is a core pattern in the Spring ActionScript framework. Included is an Operation API that will help you with creating the interfaces for the service classes, as these will have asynchronous signatures. The nice things is that there is also support for creating stub service implementations so you can test your application without relying on an actual implementation for the web or the desktop client. The framework also provides different configuration mechanism, so that you can deploy your application and provide the strategy that must be used at runtime.
I did a talk on Spring ActionScript in which I discuss the Operation API: http://parleys.com/#sl=25&st=5&id=1566
In code, your service code might something like this:
// interface
public interface IUserService {
  function getUserByID(id:String):IOperation;
}

// implementation A
public class UserServiceA implements IUserService {
  public function getUserByID(id:String):IOperation {
    // return implementation specific operation
  }
}

// implementation B
public class UserServiceB implements IUserService {
  public function getUserByID(id:String):IOperation {
    // return implementation specific operation
  }
}

The end results is that your application talks to IUserService and knows nothing about the actual implementations. The implementations can be configured and managed in the Spring ActionScript container and injected automatically for you.

A: It's a good start. You will need also to isolate platform dependant code.
See this post for some details:
File() FileStream in web app
