2017-03-10 1 views
0

github에서 저장소 세부 정보를 검색하고 반환하는 RESTful 웹 서비스를 만들고 있습니다. 내 코드는 다음과 같습니다 repositoryDetailsInternalrepositoryDetailsOutput : 당신이 볼 수 있듯이, 두 가지 중요한 개체가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는 불변이며, 값 객체처럼 보인다 이것은 저장소 상태의 스냅 샷을 나타냅니다.

+0

아마도 그게 네가 겪은거야? http://stackoverflow.com/questions/14161753/class-object-entity-whats-the-difference. IMHO (im) mutability는 변경할 수 있거나 변경할 수 없으므로 (예 : 변경되지 않는 과거 이벤트가있는 엔티티를 가질 수 있기 때문에) "엔티티가되는 것"과 직각입니다. – Piohen

답변

2

Identity이 없기 때문에 웹 서비스에서 반환 된 값이 다를 수 있지만 두 개체 모두 Value Objects이라고 말할 수 있습니다.

나는 더 복잡한 시나리오가 entities이 될 수 있다고 상상할 수 있지만, 이것이 귀하의 경우인지는 알 수 없습니다. 즉, 프로젝트에 별이있는 시점에 진화를 저장할 수 있습니다.

+0

편집을 참조하십시오. 문제에 대한 의견이 바뀌 었습니까? – Shem

+0

흠, 아니요. github 저장소는 'Entity'처럼 보이지만 Github Remote Bounded Context에서는 'Value Object'가 있습니다. –

+0

어쨌든 조언이 있으면 확신이 없으면 'Value Object' –