-
-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1298 Added the resources for Identity Field Design Pattern
- Loading branch information
Showing
6 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters