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 June 19th, 2009, 05:55 PM
Authorized User
 
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
Default Why don’t concrete DAL provider classes derive directly from…?

Hello,

I’ve started reading Asp.Net 2.0 Website programming, and got a bit stuck. Anyways, here are my questions (I had some problems wording my questions properly, so I hope they will make some sense now ):


1) On page 58 author suggests that each site module should have its own abstract DAL base class, from which we will derive concrete provider classes that provide concrete RDBMS-specific implementation. This abstract class in turn derives from base class called DataAccess.

a) Now why should abstract base providers inherit from base class called DataAccess? In other words, why don’t concrete RDBMS-specific implementations derive directly from DataAccess?

Only reason I can think of as to why concrete RDBMS-specific implementation should not be direct descendant of DataAccess class is if we plan to create more than one concrete provider classes for the same RDBMS. In that case it would make sense to have abstract DAL base class (which itself inherits from DataAccess) from which these concrete provider classes would derive?!

* Is that the main reason?! If so, then why would we ever need to create more than one provider class to specific RDBMS?



2) On same page author also talks about helper method ExecuteNonQuery(). This method can in essence translate a name of stored procedure or table name in Sql Text query into proper naming convention for a particular site ( this method is also used for executing delete, insert and update statements).

a) Now why don’t ExecuteReader and ExecuteScalar (which execute Select statements) also contain this functionality? Namely, shouldn’t name of stored procedure or table name also be translated when performing Select statements?


thanx
 
Old June 19th, 2009, 08:20 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
Only reason I can think of as to why concrete RDBMS-specific implementation should not be direct descendant of DataAccess class is if we plan to create more than one concrete provider classes for the same RDBMS.
Not exactly. The reason is to facilitate creating new concrete provider classes for different RDBMSs.

For example, for the Articles module, there is already a concrete provider for SqlServer (SqlArticlesProvider). So, if you are using SQL Server, you're all set. But let's say your boss walks into your office and says "The Oracle rep took me to lunch yesterday, and she was wearing a very short skirt, so now we're using Oracle." The fact that you have an abstract base class let's you quickly write a new OracleArticlesProvider you can use without upsetting any of the other code. Or a MySqlArticlesProvider, or VistaDbArticlesProvider, or Db2ArticlesProvider, or whatever you need.

Quote:
This method can in essence translate a name of stored procedure or table name in Sql Text query into proper naming convention for a particular site
Not sure where you're getting that. Actually, the ExecuteNonQuery method does not translate the name of anything.

It's main purpose is to provide a "demo" mode for the application, by resetting all output and return command parameters to default values in the case where the user is named "sampleeditor". That way, you can provide a universal demo login that lets a user act as an editor, but not actually alter any values in the database.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
carewithl (June 21st, 2009)
 
Old June 20th, 2009, 11:31 AM
Authorized User
 
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
Default

Hello,


Quote:
Originally Posted by Lee Dumond View Post
Not exactly. The reason is to facilitate creating new concrete provider classes for different RDBMSs.

For example, for the Articles module, there is already a concrete provider for SqlServer (SqlArticlesProvider). So, if you are using SQL Server, you're all set. But let's say your boss walks into your office and says "The Oracle rep took me to lunch yesterday, and she was wearing a very short skirt, so now we're using Oracle." The fact that you have an abstract base class let's you quickly write a new OracleArticlesProvider you can use without upsetting any of the other code. Or a MySqlArticlesProvider, or VistaDbArticlesProvider, or Db2ArticlesProvider, or whatever you need.
I understand what you’re getting at. But still, if I plan to create only one concrete provider class for Oracle RDBMS ( let us call this class C ), then it makes no difference if I derive it directly from DataAccess or from abstract DAL base class. Only if I suspected that some programmer might also want to create concrete provider for Oracle RDBMS , and would like to use same API as my class ( thus her class would have same methods and properties as C), but would like to implement some of C’s methods differently, then it would make sense that I’d create abstract base class instead( this class would have some methods already implemented – these methods being those that other programmers would never feel the need to override in derived classes ).

But if I would create concrete provider class for Oracle RDBMS for my use only, then would there really be any difference whether the concrete class derived directly from DataAccess or from abstract DAL base class?

Quote:
Originally Posted by Lee Dumond View Post
Not sure where you're getting that. Actually, the ExecuteNonQuery method does not translate the name of anything.

It's main purpose is to provide a "demo" mode for the application, by resetting all output and return command parameters to default values in the case where the user is named "sampleeditor". That way, you can provide a universal demo login that lets a user act as an editor, but not actually alter any values in the database.
From page num. 58:

“The ExecuteNonQuery function in DataAccess base class is special helper method that can be used to translate the name of the stored procedure or table names in Sql text query, into proper naming convention for particular database used by one site ( but in our case we’re not going to take it this far, in order to keep things simple )”

Judging from what the author wrote in parentheses, the ExecuteNonQuery implemented in TheBeerHouse project indeed doesn’t translate the procedure and data table names ( for the sake of simplicity ), so I guess my initial question refers to projects where ExecutenonQuery would implement name translations of stored procedures and table names.


I really appreciate your help
 
Old June 20th, 2009, 03:03 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
But still, if I plan to create only one concrete provider class for Oracle RDBMS ( let us call this class C ), then it makes no difference if I derive it directly from DataAccess or from abstract DAL base class.
Technically, that's true, but are you sure you (or the other programmers on your team) would remember all the methods that must be implemented for the data provider to work? This is the advantage of using an abstract class - it enforces a contract by forcing you to implement its abstract members when you subclass it. Because this contract is in place, you can reliably program against the abstract class intead of programming against any single concrete implementation. This is the Liskov Substitution Principle in action, and it is what allows the concrete implementations to be "pluggable", as I already explained.

Quote:
I guess my initial question refers to projects where ExecutenonQuery would implement name translations of stored procedures and table names.
Yes, in cases in which you are doing sproc/table translations in queries, you would want to implement the translation logic in all of the command methods that run against the database.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
carewithl (June 21st, 2009)
 
Old June 20th, 2009, 04:24 PM
Authorized User
 
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
Default

Hello,

Quote:
Originally Posted by Lee Dumond View Post
Yes, in cases in which you are doing sproc/table translations in queries, you would want to implement the translation logic in all of the command methods that run against the database.
Since I know the author is an expert on the subject, is there a reason why he only mentioned ExecuteNonQuery function in DataAccess class as being a special helper method that also translates the names? Why not also say that ExecuteReader and ExecuteScalar also provide this functionality? There must be a reason why he didn't do that?!

thank you very much
 
Old June 20th, 2009, 05:21 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Not really sure. He may have originally mentioned this, but some of it could have been edited out as being not directly relevant, since the final application does not utilize this functionality.

That's just a guess though. I don't read minds, only books. ;)
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
carewithl (June 21st, 2009)
 
Old June 21st, 2009, 03:13 PM
Authorized User
 
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Lee Dumond View Post
Not really sure. He may have originally mentioned this, but some of it could have been edited out as being not directly relevant, since the final application does not utilize this functionality.

That's just a guess though. I don't read minds, only books. ;)
Hopefully the author will read this thread and perhaps find some time to offer some insight

Anyways, I really appreciate your help

cheers mate
 
Old June 21st, 2009, 03:39 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Not likely. I don't think Marco is really involved in the forum any longer.

Best bet is to write him directly.

mbellinaso AT gmail DOT com
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old June 22nd, 2009, 04:12 PM
Authorized User
 
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
Default

thanx for everything mate
 
Old June 22nd, 2009, 04:20 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Anytime. Don't hesitate to ask if you have more questions.
__________________
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
DAL to BLL rodmcleay LINQ 3 June 2nd, 2008 12:15 PM
Thoughts: Entity/Provider folders in DAL jimibt BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 September 25th, 2007 05:04 AM
Redundancy in DAL/BLL classes Mourad BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 March 8th, 2007 10:39 PM
Derive TcpClient [email protected] C# 5 October 11th, 2004 11:01 PM
can we able to derive a script from mdb mrleokarthik Pro VB 6 0 November 28th, 2003 08:49 AM





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