Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separated API and Implementation Project Structure

A parent-api-impl project structure is kind of new to me. Our Java maven project structure is like this:

> com.sample.myproject
> com.sample.myproject.api    
> com.sample.myproject.impl

My questions would be:

  1. How do I create such project in Eclipse in such a way that they are connected with each other?

  2. When is this kind of structure advisable?

  3. Is there any site or reference that I can refer to, that discusses this kind of structure? A tutorial or a guide perhaps?

like image 744
learning_dev_me Avatar asked Oct 14 '13 05:10

learning_dev_me


1 Answers

I think it might make more sense to answer your questions in reverse order...

Since you have an API, the Facade Data Pattern might be a good point to start. The aim of this pattern is to essentially provide an interface to which external users can connect to.

This type of structure is usually desired when you want to expose a series of functions (an API) without divulging how you actually when about an implemented such functions. So, for instance, you just expose a public BigDecimal calculateTax(BigDecimal amount, double percentage) to your users, without showing how you went about and implemented your method.

Lastly, this is how I would do it:

  • com.sample.myproject will be my core project and in it I will put any core functionalities such as persistence of objects.

  • com.sample.myproject.api will be essentially a project with Interfaces and other things I want to expose.

  • com.sample.myproject.impl will implement the two projects above by using the core project and some extra logic to expose what API layer is making available.

like image 102
npinti Avatar answered Oct 22 '22 08:10

npinti