Skip to content
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

Static factory methods for Association #48

Closed
wants to merge 1 commit into from

Conversation

odrotbohm
Copy link
Member

Introduced Association.forAggregate(…) and ….forId(…) to easily create Association instances without having to explicitly implement it.

@odrotbohm
Copy link
Member Author

Thinking about this, I wonder how we should treat equality for Associations in general and the ones created by the factory methods in particular. I.e. should this be true or not:

SomeIdentifier identifier = new SomeIdentifier(…);
SomeAggregate aggregate = new SomeAggregate(identifier);

assertThat(Associations.forId(identifier)).isEqualTo(Association.forAggregate(aggregate));

While they're logically the same as they're pointing to the same aggregate for technical reasons, they're currently not as they're implemented using lambdas. that would be resolvable by introducing a dedicated (probably hidden) type. Even with that in place we'd have to answer how that's going to work when comparing those ad hoc Associations with custom Association implementations:

class SomeAssociation implements Association<SomeAggregate, SomeIdentifier> { /* … */ }

assertThat(SomeAssociation.of(identifier)).isEqualTo(Association.ofId(identifier));

We're never gonna get this to work symmetrically. I.e. different Association implementations can never be equal(…) in the first place. I am still leaning towards requiring that two different calls to Association.ofId(…) should produce instances that are equal. Also the assertion at the very top should be (mixing aggregate and identifier instances ultimately pointing to the same identifier).

WDYT?

odrotbohm added a commit that referenced this pull request Mar 2, 2021
Introduced Association.forAggregate(…) and ….forId(…) to easily create Association instances without having to explicitly implement it. Implementations return a SimpleAssociation that implements equals(…) and hashCode() by verifying the equality of both the actual association type and the target identifier. Introduced pointsToSameAggregateAs(…) for identifier only comparison.
@odrotbohm odrotbohm force-pushed the feature/association-factory-methods branch from fd70b98 to f8cbe17 Compare March 2, 2021 17:28
@odrotbohm odrotbohm added this to the 1.2 milestone Mar 2, 2021
@odrotbohm odrotbohm added module: ddd Domain-Driven Design related support type: enhancement New feature or request labels Mar 2, 2021
@odrotbohm
Copy link
Member Author

I've updated the feature branch with the package protected SimpleAssociation to ensure equality as described above and introduced a pointsToSameAggregateAs(…) for sole identifier comparison.

Introduced Association.forAggregate(…) and ….forId(…) to easily create Association instances without having to explicitly implement it. Implementations return a SimpleAssociation that implements equals(…) and hashCode() by verifying the equality of both the actual association type and the target identifier. Introduced pointsToSameAggregateAs(…) for identifier only comparison.
@odrotbohm odrotbohm force-pushed the feature/association-factory-methods branch from f8cbe17 to d9232e3 Compare March 2, 2021 18:01
@odrotbohm
Copy link
Member Author

Unless there are objections, I'd merge this later tonight or early morning tomorrow.

@odrotbohm odrotbohm changed the title Static factory methods for Association. Static factory methods for Association Mar 3, 2021
odrotbohm added a commit that referenced this pull request Mar 3, 2021
Introduced Association.forAggregate(…) and ….forId(…) to easily create Association instances without having to explicitly implement it. Implementations return a SimpleAssociation that implements equals(…) and hashCode() by verifying the equality of both the actual association type and the target identifier. Introduced pointsToSameAggregateAs(…) for identifier only comparison.
@odrotbohm
Copy link
Member Author

That's merged.

@odrotbohm odrotbohm closed this Mar 3, 2021
odrotbohm added a commit to xmolecules/jmolecules-integrations that referenced this pull request Mar 3, 2021
Following xmolecules/jmolecules#48 for proper equals(…)/hashCode() handling of the Association instances returned.
@odrotbohm odrotbohm deleted the feature/association-factory-methods branch August 20, 2021 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: ddd Domain-Driven Design related support type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants