Is it possible (recommended) to have a clean api project that is separate from the actual implementation?

I was asked to create a layout project for our upcoming application using Maven. The first artifact we are working on will be architecture. To make the work as easy as possible for developers, I got the idea of ​​decoupling the actual implementation from the API (for example, you would do it in the OSGi environment).

Dependencies will display the API project as a dependency for the compilation area, and implementation is provided only at runtime.

With this approach, I hope to reduce complexity for developers, as well as limit them to using inner classes that change frequently. In addition, you can hide transitive dependencies (for example, I do not want developers to call the DAO layer from the external interface ... this should only be visible from the service level).

Someone put it into practice and how did it go? What do you think of this in general?

+5
source share
4 answers

I have seen this a lot, and there are advantages and disadvantages to this approach:

  • Benefits
    • Clear separation of APIs and implementation
  • disadvantages
    • It is harder to understand because there is no real context, such as unit tests, to understand what an API is.
    • API. , , API, ( , ).
    • API () , , .

, API API, API , API , , .

:

  • API .
  • API , , API.
  • , , API .
+3

() . , , . , , . , ( ), . , , , / .

+2

UML , UML , UML , .

Enterprise Architect - . , UML, UML.

0
source

I think this is a good approach and use it all the time. I had no real flaws for this.

An example of my use is something like a library that clears the screen.

I would have a Maven project:

data-source-api

This service has:

package my.datasource.api;

public interface DataSource {
    public GetDataResponse getData(GetDataRequest request);
}

Where GetDataRequestand GetDataResponse(and other API classes) are also in the api project.

And also called Maven projects:

data-source-urlfetch-impl // for appengine
data-source-http-client-impl // for Apache HTTP client
data-source-urlconnection-impl // for appengine/vanilla Java

For each of my implementations. For instance:.

package my.datasource.urlfetch;

public class UrlFetchDataSource implements DataSource {
    ...
}
0
source

All Articles