Home arrow PHP arrow Introducing the Lazy Loading Pattern

Introducing the Lazy Loading Pattern

Welcome to the third part of a five-part series on lazy and eager loading in PHP 5. In this part of the series, you'll learn about the lazy design pattern, and how to use it effectively in your applications.

TABLE OF CONTENTS:
  1. Introducing the Lazy Loading Pattern
  2. Review: object-oriented lazy loading
  3. Introducing the lazy loading pattern
  4. Lazy loading in action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
September 17, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Very often, the terms "lazy" and "eager" are used in daily talking to define or qualify the way that certain people are, or simply to judge their behaviors and reactions in response to a number of situations that occur in life. The truth is that we, as individuals, are an interesting mixture of these two characteristics.

Also, it's true that human beings try to translate these concepts to other areas, such as software programming. If you've ever developed web-based or desktop applications using your favorite compiled or interpreted language, then it's possible that you've already coded "factory" methods to create one or multiple objects, or even defined a few "Observer" and "Dispatcher" modules as well.

Definitively, many design patterns like the ones mentioned above respond to simple translations of human behaviors within the terrain of software development, and certainly "lazy" and "eager" aren't the exception. In general, when an application uses lazy loading, it means that it delays or defers the loading of a specific resource until it's really required at runtime. On the other hand, if the same application (or a part of it) relies on eager loading, then it implies that the resource will be loaded as soon as possible, regardless of whether or not it has been requested.

Of course, it's possible to extend the concepts of "lazy" and "eager" when working with classes, which leads to using approaches commonly known as lazy and eager instantiations respectively. In the case of PHP 5, implementing lazy and eager loading is truly a no-brainer process, and the result of this implementation can be either successful or amazingly poor, depending on the context in which these patterns are applied.

Precisely, in the previous chapter of this series I developed an example that showed that there are times when including eagerly a class within a script can be pretty inefficient, especially if an instance of the class is created by the script in question right before it finishes its execution.

Nonetheless, it's possible to use the benefits of lazy loading to address an issue like this very easily, and that's exactly what I'm going to show you in the lines to come. So, if the topic interests you, start reading to find out more on it!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: