Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 2nd, 2006, 09:31 PM
Registered User
 
Join Date: Aug 2006
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.

 
Old August 2nd, 2006, 10:03 PM
Friend of Wrox
 
Join Date: Jun 2003
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






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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.