Server Error in Application

An unhandled exception occurred during the execution of the current web request
posts - 60, comments - 75, trackbacks - 50

My Links

News

Hire Me Direct My Bookmarks

Archives

Post Categories

ASP.NET

Lazy Loading

Not to load code modules into memory until you are sure you are going to be required. Example:

I am having Category and Sub-Category. Category can hold list of Sub-Category, but this sub-category is not require every time. I’ll load sub-category when it is required. I am using following code to achieve this.

 

public class Category

    {

 

      // Other Geter Seter..

 

      private List<SubCategory> _subCategories;

   /// <summary>

        /// Sub Categories

        /// </summary>

        public List<SubCategory> SubCategories

        {

            get

            {

                //Lazy Load

                if (_subCategories == null)

                    _subCategories = GetSubCategories(this.ID);

                return _subCategories;

            }

            set { _subCategories = value; }

        }

    }

 

I’ll not fill list of sub-category in default load of Category object (cunstructor or some Load method) instant of I’ll load list of sub-category when it is acthuly required.

 

 

http://www.martinfowler.com/eaaCatalog/lazyLoad.html


ASP.NET Interview Questions | C# Interview Questions | .NET Interview Questions | Dot Net Interview Questions | VB.NET Interview Questions | Oracle Interview Questions

Print | posted on Thursday, October 26, 2006 9:42 AM | Filed Under [ C# Design Pattern ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: