Skip to content

Commit

Permalink
#1298 Added the resources for Identity Field Design Pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
ASHUdev05 committed Oct 5, 2023
1 parent cb2d794 commit 724669c
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
33 changes: 33 additions & 0 deletions identity-field/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: Identity Field
category: Structural
language: en
tag:
- Enterprise Integration Pattern
---

## Also known as

> P of EAA
## Intent

> Saves a database ID field in an object to maintain an identity between an in-memory object and a database row.
## Explanation

>The Identity Field design pattern is a structural design pattern that allows you to maintain the identity of an object between the application and the database. It is also known as P of EAA, which stands for Primary Key of Entity-Attribute-Association.
>The Identity Field design pattern works by adding a field to your object that matches the primary key of the corresponding database table. This field is then used to identify the object in the database.
## Class diagram
![alt text](./etc/identity-field.urm.png "Identity-Field design pattern class diagram")

## Applicability

> Use Identity Field when there’s a mapping between objects in memory and rows in a database.
## Credits

* [P of EAA](https://martinfowler.com/eaaCatalog/identityField.html)
* [Identity field design pattern](https://www.sourcecodeexamples.net/2018/05/identity-field-pattern.html)
Binary file added identity-field/etc/identity-field.urm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions identity-field/etc/identity-field.urm.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@startuml

class Person {
+ id : long
+ name : String
+ age : int
}

Person <|-- Person

@enduml
15 changes: 15 additions & 0 deletions identity-field/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.26.0-SNAPSHOT</version>
</parent>

<artifactId>identity-field</artifactId>


</project>
44 changes: 44 additions & 0 deletions identity-field/src/main/java/com/iluwatar/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.iluwatar;

public class Person {

// The identity of the person.
private long id;

// The name of the person.
private String name;

// The age of the person.
private int age;

public Person() {}

public Person(String name, int age) {
this.name = name;
this.age = age;
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
<module>context-object</module>
<module>thread-local-storage</module>
<module>optimistic-offline-lock</module>
<module>identity-field</module>
</modules>
<repositories>
<repository>
Expand Down

0 comments on commit 724669c

Please sign in to comment.