I'm trying to implement my first domain driven application, after going through Eric Evan's book on Domain-Driven Design. I'm a bit confused on how to go about creating Value Objects.
So in my application, a user can purchase a service for getting them certain number of views on a video they post in Youtube, which is fulfilled by the other users of my app who watch those videos(Basically a replica of the many youtube promoter apps already available, for learning).
Say the service is represented in the app as an entity called WatchTime. The WatchTime entity contains some information like the MaxViews(max number of views purchased) and CurrentViews(number of views already fulfilled). The MaxViews and CurrentViews are value objects, and both are similar.
So the thing is, should I have a common 'Views' Value Object that is the type for both the MaxView and CurrentView domain concepts, something like this:
class Views extends ValueObject<Views> {
@override
bool fsameValueAs(Views other) {
// Implementation
}
int mvalue;
}
class WatchTime extends Entity<WatchTime> {
@override
bool fsameIdentityAs() {
// Implementation
}
Views mmaxViews;
Views mcurrentViews;
}
or
should I make a seperate class for MaxViews and Current Views since they are domain concept and they should be explicit, kinda like this:
class Views {}
class MaxViews extends ValueObject<MaxViews> {
// Other stuff
Views mviews;
}
class CurrentViews extends ValueObject<CurrentViews> {
//Other stuff
Views mviews;
}
class WatchTime extends Entity<WatchTime> {
@override
bool fsameIdentityAs() {
// Implementation
}
MaxViews mmaxViews;
CurrentViews mcurrentViews;
}
or
something like this:
class MaxViews extends ValueObject<MaxViews> {
// Other stuff
int mviews;
}
class CurrentViews extends ValueObject<CurrentViews> {
//Other stuff
int mviews;
}
class WatchTime extends Entity<WatchTime> {
@override
bool fsameIdentityAs() {
// Implementation
}
MaxViews mmaxViews;
CurrentViews mcurrentViews;
}
I'm not really sure how I should go about this.
I'm also not sure about another thing from the book. So I understand that making concepts of the domain explicit will make the application more clearer and easier to navigate and read. So to make something explicit, is is necessary to make it an entity or a value object with the same name as the domain class, or is the variable name being the same as the domain concept sufficient.
For example, .
class Money {}
Money mSalary;
vs
class Salary {}
Salary mSalary;
I'm pretty sure my suggestions might look very stupid, I would be happy if you could give me better suggestions. Thanks.