terminal

codeando_simple

terminal

menu

terminal

search_module

guest@codeandosimple: ~/system/search $ grep -r "" .

Press [ENTER] to execute search

Status

Engine: Ready

Database: Online

Index: V2.1.0_LATEST

bash -- cat identity-map.md
guest@codeandosimple: ~/enterprise/patterns $ cat identity-map.md

Identity Map_

// "A single object for each record in memory"

The **Identity Map** pattern ensures that each business object is loaded only once from the database in a single session.

It works as an internal session cache: when you request an object by its ID, the Identity Map first checks if it already has it in memory. If so, it returns the existing instance instead of querying the database again.

# Key Benefits

  • check_circle

    Identity Consistency

    Avoids having two different objects in memory representing the same database row.

  • check_circle

    Performance

    Drastically reduces repetitive database queries.

# Practical Example

if (map.containsKey(id)) {
    return map.get(id); // Returns already loaded object
} else {
    Person p = db.loadPerson(id);
    map.put(id, p); // Saves it for next time
    return p;
}