what actaully meant by lazy,eager,explicit loading?
i recently came to know about lazy,explicit and eager loading as i was attending meetin开发者_StackOverflow社区g for my new project? But,i didn't get that why we are studying that? I was to work on a silverlight project which also include WCF RIA services.My mentor was explaining these types of loading. Can any one help me out so that i can study them and show my mentor that how serious i am in a task which is assigned to me.
Say you have a CustomerOrder class, and this class has a MyCustomer property and a MySalesOrderLines property. The MyCustomer property contains a reference to the Customer class that represents the customer of the order, while the MySalesOrderLines property contains a reference to a collection of order lines for the order. In Lazy Loading, the databse records that these properties return are not retrieved from the database until they are actually called via code. ie, When retrieving a Lazy-Loaded CustomerOrder instance from the database, only when there is a line of code that refers to CustomerOrder.MyCustomer is the Customer instance retrieved from the database. In eager loading, these properties are retrieved from the database at the same time as when the CustomerOrder record is retrieved from the database.
lazy loading is like images load when we do scrolling not before than that
Oh, since you mentioned WCF RIA I suppose your boss was talking about these patterns in terms of resource acquisition. You could also talk about laziness in terms of instantiation (objects), loading (shared libraries), state (object state initialization), evaluation (expressions not being evaluated until the result is used). Same thing probably applies to the other pattern names in different use cases. If its about resource management then...
These are patterns related to object acquisition and are described in detail in [POSA3 Pattern Oriented Software Architecture: Patterns for Resource Management, vol 3][1].
Resource management (you can think objects but resource is a better term) is organized in four stages: lookup, acquisition, lifecycle and release. The patterns you are asking for are resource acquisition patterns.
After you successfully lookup a resource, you have 4 strategies to choose from for acquiring the resource:
explicit acquisition, when the resource is to be fully acquired when requested; this is no pattern but a normal usecase
lazy acquisition, when the acquisition of the resource can be deferred in a later point in time, at the moment when the object properties are accessed (you will return a proxy object initially).
eager acquisition strategy allows you do predictive resource acquisition (that is, you want to acquire immediately a set of resources that you know will be asked for in the lifecycle of initial resource being requested
partial acquisition strategy allows you to do staged acquisition; think of big-memory/uknown-size objects, initially you will want to acquire the object only partially
精彩评论