Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 2nd, 2006, 09:31 PM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default SiteProvider Question

ArticlesProvider class, among other classes has the static "Instance" property that returns an instance of well... ArticlesProvider. Why is it implemented as such:

...
static public ArticlesProvider Instance
{
   get
   {
      if (_instance == null)
         _instance = (ArticlesProvider)Activator.CreateInstance(
          Type.GetType(Globals.Settings.Articles.ProviderTyp e));
      return _instance;
   }
}
...

Why can't you return an instance of it like so:

...
_instance = new ArticlesProvider();
return _instance;
...

Can someone comment on this, it is bothering me and I really need to know. Thanks in advance.

  #2 (permalink)  
Old August 2nd, 2006, 10:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

He wants to make sure there will only be one class instance. Do some web searches for the Singleton Design Pattern. This is also a lazy loading design that doesn'tconstruct the instance until the first request comes in. After that, all future requests get the same instance and not a new one.
  I can't check the source right now, but you may find that ArticlesProvider has no public constructor, since that would bypass the purpose of what we're trying to do if people could create their own instance.
  Lastly, as if that weren't enough, he's dynamically fetching the type from the global settings and creating it based on that type. That allows the provider to change in the future without changing this source code.

Eric

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SiteProvider Reza BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 9 September 7th, 2008 04:04 PM
question Harjinder .NET Framework 2.0 1 July 29th, 2008 05:41 AM
Chapter 5 Aricles/SiteProvider question HELP PLS crazy BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 9 March 7th, 2008 01:10 PM
Question? Calibus Classic ASP Databases 8 August 6th, 2004 08:25 AM



All times are GMT -4. The time now is 07:50 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.