I'm trying to figure out how to create abstraction over different APIs, which have common things. For example let's take the mobile platforms you have Android, Windows Phone and IOS. Let's say I want to create and API or program or domain-specific language, which will allow me to write one program and work on all of the given platforms. Of course this is just an example, and in the end all of the platforms have a lot in common which allow me to write programs and libraries without thinking too much about the abstraction, for example all of them have C compiler. A better example is ERP systems, let's say I want to write the same plugin for 3 different ERP systems, how could I create abstraction above their APIs which will allow me to write it once, and compile it(build it or whatever you can call it), and use it on all the systems. For the sake of simplicity let's say that those ERP system are all writing in the same programming language, but their API have nothing or little in common in terms of function names etc.. they only have similar functionality. I've though about using metaprogramming, in such way that I tell the program what I want, and using set of rules different for every API will output programs for every one of the API. Another think what I've thought of is encapsulate all of the common features in classes, which will hold the code(data) for every API, and output it when I request the functionality for given API. I'll give an example. Let's say I've 3 api which all have class for printing, and the names are like follows:
- Printer - PrintToLog(Data)
- Outputer - OutputToLog(Data, lenght)
- IO - PrntLogData(Data, logPtr)
For the sake of simplicity let all those classes be static.
I could create class like this(pseudo-code)
Class Printer{
api //holds for which API the code is requested
constructor(API){
this.api = API
}
func logData(Data){
switch API{
case API_1 //let's say the API are stored in ENUM or something similar
return "PrintToLog(" + Data + ")"
case API_2
return "OutputToLog(" + Data + "," + len(Data) + ")" // len returns the lenght of data
case API_3
return "PrntLogData(" + Data + ", /default/log/location)"
}
}
}
However I'm not sure how practical,reliable are those methods. Also I wasn't able to find a lot of information for those types for creating abstraction. Are there any sets of patterns, methodologies or principles for such abstractions?