Skip to content

Commit

Permalink
GH-57 - Introduce @Identity in DDD annotations.
Browse files Browse the repository at this point in the history
Although not an original concept within the DDD book, an identifier is already part of the type based domain language in the DDD module. For symmetry reasons it's reasonable to also allow to express the concept as annotation. We went for Identity (over Identifier) for the following reason the annotation is used on a field declaration. The field is not the identifier itself but the value held in the field. I.e. the field's value constitutes the identity of the surrounding type.
  • Loading branch information
odrotbohm committed Aug 20, 2021
1 parent 2d89b5e commit 3774d6c
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jmolecules.ddd.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Declares a field of a class to constitute the identity of the corresponding class. Primarily used in
* {@link AggregateRoot} and {@link Entity} types.
*
* @author Oliver Drotbohm
* @author Stephan Pirnbaum
* @author Henning Schwentner
* @since 1.3
* @see <a href="https://domainlanguage.com/wp-content/uploads/2016/05/DDD_Reference_2015-03.pdf">Domain-Driven Design
* Reference (Evans) - Entities</a>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE })
@Documented
public @interface Identity {}

0 comments on commit 3774d6c

Please sign in to comment.