2/6/10

Lazy loading with attributes over php

class BaseClass
{
protected function __get_xml()
{
$str = ''; for ($n = 0; $n < 10; $n++) $str .= 'XML';
return $str;
}
}


class LazyClassAtribute extends BaseClass
{
public function __get( $name )
{
$method_name = "__get_{$name}";
if ( method_exists( $this, $method_name ) ) return $this->$name = $this->$method_name();
}
}


class LazyClassRegistry extends BaseClass
{
public $cachedXml = null;


public function getXml()
{
if ( $this->cachedXml === null ) $this->cachedXml = $this->__get_xml();
return $this->cachedXml;
}
}


class NonLazyClass extends BaseClass
{
public function getXml()
{
return $this->__get_xml();
}
}

1 comentario:

  1. Air Jordan 5'4" Black | Air Jordan 5'4" Black | Air Jordan 5'4" | Air Jordan 5'4"
    This review is done from the inside air jordan 18 retro yellow shop look at the new air Jordan where can you buy air jordan 18 retro racer blue 5'4 and Air air jordan 18 retro men red online Jordan great jordan 18 white royal blue 5'4 Black. It's a standard 인싸 포커 size, two piece black leather travel case with two

    ResponderEliminar