Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

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

Avatar

Level 2

Currently each component gets a Java interface written. It also gets an impl class that uses annotations like @ValueMapValue and @getter 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?

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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.

View solution in original post

1 Reply

Avatar

Correct answer by
Employee Advisor

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.