 |
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
|
|
|
|
|

June 19th, 2009, 05:55 PM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 19th, 2009, 08:20 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
|
|
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.
|
|
The Following User Says Thank You to Lee Dumond For This Useful Post:
|
|
|

June 20th, 2009, 11:31 AM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
|
|
Hello,
Quote:
Originally Posted by Lee Dumond
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
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
|
|

June 20th, 2009, 03:03 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
|
|
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.
|
|
The Following User Says Thank You to Lee Dumond For This Useful Post:
|
|
|

June 20th, 2009, 04:24 PM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
|
|
Hello,
Quote:
Originally Posted by Lee Dumond
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
|
|

June 20th, 2009, 05:21 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
|
|
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. ;)
|
|
The Following User Says Thank You to Lee Dumond For This Useful Post:
|
|
|

June 21st, 2009, 03:13 PM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Lee Dumond
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
|
|

June 21st, 2009, 03:39 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
|
|
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
|
|

June 22nd, 2009, 04:12 PM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
|
|
thanx for everything mate
|
|

June 22nd, 2009, 04:20 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
|
|
Anytime. Don't hesitate to ask if you have more questions.
|
|
 |