Question

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?

Was it helpful?

Solution 2

1) In eclipse you create the 3 project and make a pom.xml file for each for the maven management. After this, you should make:

  • parent depend on api
  • impl depend on parent and api

This way the eclipse m2eclipse plugin will connect the projects to each other.

2) This project structure is only advisable if you will ever need to change the whole implementation of the defined api. It allows you to place another jar with another implementation to the application easily, without modifiing any java code. Of course it's only applicable if you are refering to the api only, through and not the implementation. It can be accomplished with EJB or Spring.

3) I can't think of any tutorials or sites out there, sorry.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top