github에서 저장소 세부 정보를 검색하고 반환하는 RESTful 웹 서비스를 만들고 있습니다. 내 코드는 다음과 같습니다 repositoryDetailsInternal
및 repositoryDetailsOutput
: 당신이 볼 수 있듯이, 두 가지 중요한 개체가Entity vs ValueObject
@GetMapping(value = "/{owner}/{repositoryName}")
@ResponseStatus(HttpStatus.OK)
public RepositoryDetails getRepositoryDetails(@PathVariable String owner, @PathVariable String repositoryName) throws Exception {
log.info("Github repository details request: owner: " + owner + ", repository name: " + repositoryName);
checkParameters(owner, repositoryName);
RepositoryDetailsInternal repositoryDetailsInternal = repoService.getRepositoryDetails(owner, repositoryName);
RepositoryDetails repositoryDetailsOutput = new RepositoryDetails(repositoryDetailsInternal, LocaleContextHolder.getLocale());
return repositoryDetailsOutput;
}
. repositoryDetailsInternal
은 Github에서 파싱 된 응답 데이터이고 repositoryDetailsOutput
은 내 웹 서비스에서 반환하는 출력 개체입니다.
내 질문은 다음과 같습니다. 각각의 개체 - 개체 또는 값 개체는 무엇입니까?
저는 repositoryDetailsInternal
엔터티와 repositoryDetailsOutput
값 개체를 호출하는쪽으로 기울어 져 있습니다.하지만 그것에 대한 몇 가지 의견을 말씀 드리고 싶습니다.
한편, repositoryDetailsInternal
은 시간이 지남에 따라 변경 될 수있는 항목입니다 (실무 그룹 수를 늘리거나 줄일 수 있음). 반면에 내 응용 프로그램에서는이 개체를 변경할 수 없습니다.
편집 : 나는 또한 repositoryDetailsInternal
소유자 및 저장소 이름를 사용하여 캐시 된 것을 언급해야한다, 그래서는 ID로 인식 될 수 있기 때문에,
@Cacheable(REPO_DETAILS_CACHE)
public RepositoryDetailsInternal getRepositoryDetails(String owner, String repositoryName) throws TimeoutException {...}
repositoryDetailsOutput
는 불변이며, 값 객체처럼 보인다 이것은 저장소 상태의 스냅 샷을 나타냅니다.
아마도 그게 네가 겪은거야? http://stackoverflow.com/questions/14161753/class-object-entity-whats-the-difference. IMHO (im) mutability는 변경할 수 있거나 변경할 수 없으므로 (예 : 변경되지 않는 과거 이벤트가있는 엔티티를 가질 수 있기 때문에) "엔티티가되는 것"과 직각입니다. – Piohen