Reputation: 565
I'm creating a RESTful webservice, which retrieves repository details from github and returns them. My code looks like this:
@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;
}
As you can see, there are two important objects: repositoryDetailsInternal
and repositoryDetailsOutput
. repositoryDetailsInternal
is the parsed response data from Github and repositoryDetailsOutput
is the output object returned by my webservice.
My question is: what is each of these objects - an entity or a value object?
I'm leaning towards calling repositoryDetailsInternal
an entity and repositoryDetailsOutput
a value object, but I'd like some second opinion on that.
On one hand, repositoryDetailsInternal
is something that can be changed over time (stargazers count can increase or decrease), but on the other hand in my application this object is immutable.
EDIT: I should also mention that repositoryDetailsInternal
is cached using owner and repository name, so it may be perceived as identity:
@Cacheable(REPO_DETAILS_CACHE)
public RepositoryDetailsInternal getRepositoryDetails(String owner, String repositoryName) throws TimeoutException {...}
repositoryDetailsOutput
is also immutable and seems like a value object, because it represents a kind of a snapshot of repository state.
Upvotes: 0
Views: 398
Reputation: 17683
From what I can tell both objects are Value Objects
even if the value returned by the web service can vary because they don't have an Identity
.
I can imagine a more complex scenario in which they could become entities
but I don't know if this is your case (i.e. you could store an evolution in time of the stars a project has).
Upvotes: 2