By Carlos Martinez.
Repository Pattern
The repository is useful when trying to separate the domain logic from the logic that retrieves the data and maps it in entity objects.
The repository is a small layer between the data source layer and the upper domain layers of the application. Gets the data from the data source and retrieves it to the upper layers. Also the repository contains the persistence logic of the domain objects. This logic separation has 3 benefits:
· The logic for web services and data are centralized
· It simplified the unit test.
· It provides a flexible architecture that can be adapted as the overall design of the application evolves.
Lazy & Eager Loading
When working with roots objects, a common issue is that sometimes it is need to navigate to his child properties, but those values are not needed at all times, that’s why is not recommendable to load all values any time the root object is loaded.
There are four main varieties of lazy load. Lazy Initialization uses a special marker value (usually null) to indicate a field isn't loaded. Every access to the field checks the field for the marker value and if unloaded, loads it. Virtual Proxy is an object with the same interface as the real object. The first time one of its methods are called it loads the real the object and then delegates. Value Holder is an object with a getValue method. Clients call getValue to get the real object, the first call triggers the load. A ghost is the real object without any data. The first time you call a method the ghost loads the full data into its fields.
When using Eager loading, the attempted situation is to get all the data from the sources, with a minimum amount of queries in the process. So the code can archive some level of performance by avoiding querying multiple times the same data.