In this post,i will try to explain identity map pattern. The most basic definition of identity map pattern is “Ensures that each object gets loaded only once by keeping every loaded object in a map. Looks up objects using the map when referring to them.” via Martin Fowler . This pattern is Data access pattern in enterprise design pattern.you should situate inside data access mechanism(data access layer) of your applications.This pattern can name as “track mapper“,”entity mapper”.
Let’s talk about a few significant points,step by step
- Identity map is closely related to data mapper and object pooling pattern
- All objects retrived data of object from database.Pattern prevents this case
- It provider own object cache for objects When you look at a different perspective
- Identity map mechanism prevents objects representing the same object/row/data
- This pattern is not trivial.Cause reduce the spent time for data getting
- You won’t need to fear about object duplications
- You might have multiple object representing the same data,and there may be conflicts if the two object try to update data without being aware of each other.
You can rove for understanding identity map pattern in below diagram
Let’s coding !
Now, Visualize our code with class diagram
have a good coding my colleagues 😀 see in another post