Best practice for component Java backers? Interface only or implement it as well? | Community
Skip to main content
Art_Bird
Level 2
January 10, 2022
Solved

Best practice for component Java backers? Interface only or implement it as well?

  • January 10, 2022
  • 1 reply
  • 762 views

Currently each component gets a Java interface written. It also gets an impl class that uses annotations like @ValueMapValue and @14766979 in place of writing the actual getter and setters. We do this for everything regardless of how basic the component is.

 

I've seen some blog posts that suggest you only create an interface and use the annotations like @ValueMapValue in it. This removes the need to create the impl class as well as unit tests.

 

What would be considered the recommended/best practice in this case?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by milind_bachani

Hi @art_bird ,

The recommended practice is to have a class for each of the component, since each component might have a business logic which is not very generic. Also, having Junit for all of them makes the code more reliable depending on the test suite developed.

However, if you have a project which has all the classes that does not have any business logic then you can implement a generic class implementing the generic interface with @ValueMapValue.

You can make the call of implementation based on the project requirement and future scope.

 

Thanks.

1 reply

milind_bachani
Adobe Employee
milind_bachaniAdobe EmployeeAccepted solution
Adobe Employee
January 11, 2022

Hi @art_bird ,

The recommended practice is to have a class for each of the component, since each component might have a business logic which is not very generic. Also, having Junit for all of them makes the code more reliable depending on the test suite developed.

However, if you have a project which has all the classes that does not have any business logic then you can implement a generic class implementing the generic interface with @ValueMapValue.

You can make the call of implementation based on the project requirement and future scope.

 

Thanks.