Views: 35.2K
Replies: 4
Archived
|
Lazy Loading in Windows FormsHi,
I have a question: can we use the Lazy Loading pattern in Windows application? Appreciate if someone would explain this with some examples. Thanks Jebby Philip Jebby Philip, Mar 15, 2010
|
|
Reply 1Another example is when you need to access a parent object in your object graph. For example, if you have an Invoice and you want to know the Customer of this Invoice, it will be more easy to say :
Invoice.Customer.Name private Customer _customer; public Customer Customer { get { if (_customer == null) { _customer = GetCustomerById( Id ); } return _customer; } } Redha Reghioua, Apr 25, 2010
|
|
Reply 2Thanks Shiva, Juan, Syed
Jebby Philip, Mar 24, 2010
|
|
Reply 3Lazy loading is just a fancy name given to the process of intializing a class when it's actually needed. You might already be doing it.
For example suppose you are maintaining a collection of orders on the form and it's a class level variable, which you will fill thought out the life time of the form. Since you know that you are going to use this collection you may say while declaring at form level private List<orders> myOrders = new List<orders>(); or you may choose to lazy load it private List<orders> myOrders; and then in you form when you add the first item you do this if ( myOrders == null) myOrders = new List<orders>(); myOrders.add (firstOrder); Syed Saqib Ali Tipu, Mar 20, 2010
|
|
Reply 4Yes, you can. Lazy loading is nothing but deferring the loading of constiuent objects (referenced objects) of a class until it is required/accessed. May be this would help: http://www.lhotka.net/Article.aspx?id=48548dc3-3b64-4bb3-bc84-9476b8f77600
Siva M, Mar 19, 2010
Good explanation
Mar 13, 2010
|