M
M
Maxim2021-07-09 20:51:07
Java
Maxim, 2021-07-09 20:51:07

How to properly organize a facade for a service?

Help me figure it out, there is a Spring Boot application, you need to make a facade, the "feature" is what we get Map from the controller into the facade method, we return PageDto, universal pagination is written, the getPageDto method, this method with the same parameters and the same return type, should demonstrate different behavior (output all posts or by user/topic...)

@Service("post")
public class PostDtoFacadeServiceImpl implements PostDtoFacadeService {

private PostDtoService postDtoService; // интерфейс для разных реализаций postdtoseervice

@Autowired
public PostDtoFacadeServiceImpl(@Qualifier("allPosts") PostDtoService postDtoService) {
    this.postDtoService = postDtoService;
}

@Override
public PageDto<PostDto> callMethodByMethodName(Map<String, Object> parameters) {
    return postDtoService.getPageDto(parameters);
}

it is planned that there will be several classes in the service, each with its own implementation for the getPageDto method, everything works fine with Qualifier!
The question is: how can you make the facade universal, in order to take the name of the class from the map (or otherwise) (via the interface) and implement the implementation of exactly that class method, so as not to go into the facade with your hands, but simply pass the name in the controller . Is it even possible to do something like this? Thank you for your attention and replies!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question