-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should we have base types to avoid boilerplate code? #33
Comments
There are already building block types in jMolecules that follow the type constraints outlined in John Sullivan's Advancing Enterprise DDD blog post. I just checked our interfaces and it looks like they deserve a round of polish. PR coming. Regarding
Summarizing, the existence of |
Where did y'all land on the |
I am still not sure we want to get in the business of defining domain implementation classes as it's way too easy for them to become unusable in a certain technical context which is at odds with the importance their sole existence implies, should we ship them. For now, I'd vote those implementations to live in a dedicated, separate library, so that's an opt-in and also is slightly less prominent than the interfaces and annotations we ship as core jMolecules. For all already existing technology integration, we just recently decided to move code of similar kind into a separate repository so that it can be released independently and is also perceived as something "transitive". Does that make sense? |
The DDDBITS provide two kinds of things:
From the DDDBITS documentation:
Entities
From the Blue Book we know that entities must have an identity.
Typically we want that
equals()
andhashcode()
are based on this identity.The base class
Entity<ID>
provides implementations for this.Example:
Value Objects
Since we don't have value types in Java yet, we have to simulate values with objects.
(That may change with the advent of Project Valhalla.)
For the time being, this means unfortunately that we have to write a lot of boilerplate code for a well-implemented value object.
DDDBITS provide so called tiny types that help to reduce that boilerplate code for simple value types.
Example:
Value Objects are identityless and immutable.
Immutability in Java comes with only final fields plus methods that never mutate the state.
(That means we only have commands in the sense of command-query-separation[3].)
No identity in Java is reached by overwriting
equals()
with an implementation that is based on the values of the fields.Such an implementation and similar implementations for
hashcode()
andtoString()
are provide by theTinyType<V>
super class.Something similar could be done with Lombok, but many projects do not want to couple their domain layer to a technical library.
The text was updated successfully, but these errors were encountered: