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 July 7th, 2009, 05:38 PM
Authorized User
 
Join Date: Mar 2009
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default SiteProvider MethodName scope?

In the SqlArticlesProvider, I added a new Public method to retrieve something from the database. In Visual Studio, the new method is not shown by Intellisense using the SiteProvider approach -- SiteProvider.Articles. If I use "new SqlArticlesProvider()." the new class appears in the Intellisense list.

What am I missing? Must all methods in SqlArticlesProvider be public overrides of an abstracted class defined in ArticlesProvider?

Thanks in advance for any help.
Tom
 
Old July 8th, 2009, 07:36 AM
Authorized User
 
Join Date: Mar 2009
Posts: 75
Thanks: 16
Thanked 1 Time in 1 Post
Default

Hi,
SiteProvider.Articles points to an abstract ArticlesProvider's static function which creates an instance of needed provider class, in this case SqlArticlesProvider. (SqlArticlesProvider implements ArticlesProvider) and returns it as ArticlesProvider.

So, SiteProvider.Articles "sees" only function known to him.

What you can do: define your new function as "public abstract" in ArticlesProvider and implement it SqlArticlesProvider.

Or as you just did, create a new instance of SqlArticlesProvider class and use it as object.

Last edited by yevi; July 8th, 2009 at 07:42 AM..
 
Old July 8th, 2009, 04:52 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
Originally Posted by tdewey View Post

What am I missing? Must all methods in SqlArticlesProvider be public overrides of an abstracted class defined in ArticlesProvider?

Tom
Essentially, yes. The Liskov Substitution Principle again.

This is because the application is written to be able to work against any provider that implements ArticlesProvider.

The actual concrete provider implementation is determined by using reflection at runtime. The actual inside nuts and bolts of any particular concrete provider does not matter to the methods that call it. Because they all implement ArticlesProvider, the caller knows that the abstract methods and properties of ArticlesProvider are guaranteed to be available.

SiteProvider.Articles is of type ArticlesProvider, so if you program against SiteProvider.Articles, it can only "see" the members defined in ArticlesProvider.

If any new methods are "exclusive" to a class, and not first defined as abstract in ArticlesProvider, then there is no way that Intellisense can know about them.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}





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
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
the scope of variable ccj_999 C++ Programming 9 October 26th, 2006 10:35 AM
SiteProvider Question zmijasu2k3 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 August 2nd, 2006 10:03 PM
Scope of array jakeone Beginning PHP 1 November 4th, 2003 08:10 PM





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