I am currently creating a view object from a search result (which comes from another separate resource) as follows:
ViewObject vo = searchResultToViewObjectMapper.map(searchResult);
It works great.
However, now I want to add some pictures. These figures are a URL, and I can only determine their location through some other resource than the search result.
My first thought would be to use the Builder template, this would be:
ViewObject vo = viewObjectBuilder.build(searchResult);
and viewObjectBuilder will do something like this:
private SomeOtherResourceRepository someOtherResourceRepo; private SomeUrlBuilder someUrlBuilder; private SearchResultToViewObjectMapper searchResultToViewObjectMapper; public ViewObject build(SearchResult) { ViewObject vo = searchResultToViewObjectMapper.map(searchResult); String reference = someOtherResourceRepo.getOtherResource(searchResult); String urlToOtherResource = someUrlBuilder.build(reference); vo.setUrlToOtherResource(reference); return vo; }
The question is, is this good for this? Or are there other (better) ways? I am also wondering how the DDD approach will do this.
Thanks in advance!
source share