private string _body = null;
public string Body
{
get
{
if (_body == null)
_body = SiteProvider.Articles.GetArticleBody(this.ID);
return _body;
}
set
{
_body = value;
}
}
The Body property is interesting because it implements the lazy load pattern discussed earlier in this chapter. The Body field is retrieved by the getter function when the value of the Body property is requested by another class. Therefore, if the Body property is not accessed, this data will not be read from the database. Once it is requested and fetched, it will be held in memory in case it's requested again. If the private _body field is null it means that it wasn't loaded yet, so it's fetched by means of the DAL's GetArticleBody method and saved for possible use later. Thus, this Body property is providing lazy load and caching functionality, each of which enhance performance.