Posts

Showing posts with the label Object-Relational Behavioral Patterns

Lazy Loading Pattern

Image
Intent An object that doesn�t contain all of the data you need but knows how to get it. This pattern is commonly found in most of the OR mappers, e.g. Hibernate. Example When you load the company from company  table, you may or may not want to load employees data from the employees  table. Using Lazy Load pattern, you load  company from  company  table , and  employees  data can be loaded when it is needed. Key Points One object can have the effect of loading a huge number of related objects�something that hurts performance when only a few of the objects are actually needed. Lazy loading is a concept where we delay the loading of an object until the point where we need it. In simple words, Lazy loading is a software design pattern where the initialization of an object occurs only when it is actually needed and not before to preserve the simplicity of usage and improve performance. Applicability Use the Lazy Loading idiom when eager loading is expensive...

Identity Map Pattern

Image
This pattern belongs to  Object-Relational Behavioral Patterns  Catalog and this Catalog belongs to  Patterns of Enterprise Application Architecture . Intent 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. An Identity Map keeps a record of all objects that have been read from the database in a single business transaction. Whenever you want an object, you check the Identity Map first to see if you already have it. How It Works The basic idea behind the Identity Map is to have a series of maps containing objects that have been pulled from the database. In a simple case, with an isomorphic schema, you�ll have one Map per database table.  When you load an object from the database, you first check the map. If there�s an object in it that corresponds to the one you�re loading, you return it. If not, you go to the database, putting the objects on the map for future...

Unit Of Work

Image
This pattern belongs to  Object-Relational Behavioral Patterns  Catalog and this Catalog belongs to  Patterns of Enterprise Application Architecture . Intent When a business transaction is completed, all these updates are sent as one big unit of work to be persisted in a database in one go so as to minimize database trips. Explanation Unit of Work design pattern does two important things: first, it maintains in-memory updates and second it sends these in-memory updates as one transaction to the database. So to achieve the above goals it goes through two steps: It maintains lists of business objects in-memory which have been changed (inserted, updated, or deleted) during a transaction. Once the transaction is completed, all these updates are sent as one big unit of work to be persisted physically in a database in one go. What is � Work � and � Unit � in a software application? A simple definition of Work means performing some task.  From a software appl...