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 tha
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.