Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 OOP folks, a little conceptual help.

Author  Topic 

Sitka
Aged Yak Warrior

571 Posts

Posted - 2005-12-09 : 11:58:03
in the middle of this article

http://www.15seconds.com/issue/050721.htm

at this section

Database Objects using Managed Code

This fellow is building procs as methods of the Authors class.

What are those methods returning? Is there some kind of assumption that calling those methods populates a base collection or table in the Authors class. Or is the Authors class that base collection table?

Both ideas above seem like a stretch to me and certainly make me say WHY? But that's why I'm asking.

Thanks

Kept reading, I remember this now. Still seems an extra layer but I guess that is the point of the article.

"it's definitely useless and maybe harmful".

jhermiz

3564 Posts

Posted - 2005-12-09 : 14:11:25
Uses SQL Pipe and the context classes so it returns data to the calling process.

Where do you feel is the extra level? I think he is actually missing a tier, I would create a validation tier as well.



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-12-09 : 14:14:41
You could however put the validation tier within the business logic layer but if this is a huge app and can throw errors or exceptions I would seperate those errors / exceptions into a different tier. That way the code looks a lot less in the BL layer. Other programmers could just call AuthorExcept class and not worry about the details of how AuthorExcept class works...

Instead of:

If blah = blah blah then...
'handle error
exit routine
else
'handle something else
end if

Could be changed to
AuthorExcept e = new AuthorExcept e

If(e.isGood())
'do something
else
'do something else
end if




Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Go to Top of Page

Sitka
Aged Yak Warrior

571 Posts

Posted - 2005-12-09 : 15:12:38
I think what I'm getting at is that the Authors class is just full of commands.
It dosen't represent an actual object(persons) or set of them. The data store might be such a representation but calling the stored procedure C# object Authors confused me. The real Authors class gets built later in the next part of the article. So I'm guessing it is my inexperience with OOP that makes this not obvious to me. GetAuthors() should return something other than void, I would expected it to return the set of Authors. That is why I said I guess that is the point of the article. void Authors.GetAuthors() is "understood" as just an intermediate step (just as SQL procs would be lined up in object browser) or does not have any previous knowledge of the bigger picture. The "more real" DataTable GetAuthors() of the AuthorsBiz class. That's how it registered with me anyways.


(After all right now I keep thinking that since there are User defined types as classes of .NET. an ideal programmers database can be reduced to a singularity, one table, one column, one row. Call the type "everthing" and have at it. Since the class definition is maintained in the database it's just as practical as building tables isn't it.)

"it's definitely useless and maybe harmful".
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-12-09 : 16:16:30
Well that function actually returns exactly what you want. The signature is void, but using the send method of the pipe class sends data back to the calle.


Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Go to Top of Page

Sitka
Aged Yak Warrior

571 Posts

Posted - 2005-12-09 : 16:45:47
And what catches the data at the caller? So the Authors class (the way I'm seeing it) is incomplete in the simplistic (farmer) sense.

"Yeah we can send your data over for you but untill you further develop a class
out of this one it does you no good."

See where I'm getting hung up. GetAuthors is not gonna do someone who instantiates an Authors class any good. They call Authors.GetAuthors(), nothing, correct?

like you couldn't do this?

DataTable dt = new DataTable();
dt = Authors.GetAuthors();


Also,
why at this layer would someone think the natural name for this class is Authors?

"it's definitely useless and maybe harmful".
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-12-09 : 16:56:01
Ill be honest the author does not do a good job explaining an n-tier solution, hence his rating or the rating of the article. Why he named it Authors, I have no clue, but I think the point he is trying to make is how the CLR works and how n-tiers should be laid out.

You are right and it could be misleading to many as to the way he wrote some of this up. He did not mention about some precautions like first do this before you call this...

You probably need a more in depth look at OOP rather than a quick article with some key points. His get authors would fail if you instantiated a Authors object...

What I think he should of done is:

AuthorBL b = new AuthorBL()
--more code here including offering another tier..a validation tier to ensure that
--the business logic is correct, or include the validation inside of the BL

inside of AuthorBL:

AuthorDA d = new AuthorDA()
d.getAuthors() --data access level here
--return results to business logic layer

presentation layer simply presents the data. The code is incomplete (that is the code in the article so you are missing a piece of the pie). Actually what is an object without any entities ? Absolutely useless, when I say:

MineSweeper m = new MineSweeper
//more code here...

I expect that m is a valid mine sweeper object, in that I should be able to actually have a valid mine sweeper board immediately after constructing a MineSweeper object...one should never:

MineSweeper m = new MineSweeper
m.CreateMatrix(9, 9)
m.FillBombs(25)
m.ShowIt()

That should never be the case, the object should be ready to use after constructing it (in addition the minute I'm done constructing the object, 2nd line after construction). So his article fails to address this as well. I would recommend probably doing a search for another article or a good programming book. You know whose good, has nothing to do with ASP.net but Bruce Eckel has good Java / C++ examples of how to create objects in a OOP mindset.

Jon



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2005-12-09 : 17:36:42
"n-Tier Application"
Definition: A way to under utilise a RDBMS.

DavidM

Intelligent Design is NOT science.

A front-end is something that tries to violate a back-end.
Go to Top of Page

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2005-12-09 : 18:20:05
quote:
Originally posted by byrmol

"n-Tier Application"
Definition: A way to under utilise a RDBMS.

DavidM

Intelligent Design is NOT science.

A front-end is something that tries to violate a back-end.



I totally agree with that statement
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-12-09 : 19:51:19
quote:
Originally posted by byrmol

"n-Tier Application"
Definition: A way to under utilise a RDBMS.

DavidM

Intelligent Design is NOT science.

A front-end is something that tries to violate a back-end.



only if n > 2, of course!
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-12-09 : 20:51:51
Another vote for the anti-n-tier ballot. And n-tier is SOOOOOOO early-21st century anyway; don't you know you're supposed to do everything with XML and web services now?
quote:
You could however put the validation tier within the business logic layer but if this is a huge app and can throw errors or exceptions I would seperate those errors / exceptions into a different tier.
What's wrong with having validation in the database? Business Layer validation is no substitute for database validation (although it's a very nice complement). And keeping the logic closer to the database reduces or eliminates the need to throw errors between tiers (talk about underutilizing a technology, if errors and exceptions are a key communication between tiers)

There isn't a single thing in that article that couldn't be done (better) as a (purely T-SQL) stored procedure. With the additional benefits of:

1) direct integration with the database (BTW, it's not a LAYER or TIER);
2) more flexible abstraction/API that can be reused and ported to non-.Net platforms like Java, PHP, or even earlier versions of SQL Server;
3) more clearly defined and implemented rules, also more easily changeable;
4) possibly better performance, if the .Net overhead is substantial (cursors anyone?);
5) better security (SqlCommand and parameters notwithstanding, the GetTitlesByAuthor code is a carbon copy of every SQL injection example I've ever seen)

While this article isn't the worst SQL.Net example I've seen, it's definitely a "let's fix what was never broken" approach to a problem. I see some advantage in being able to reform the output into different classes (Reader, Record, Error, String) but certainly not enough to construct an architecture with. And this is IMHO the silliest part of the article:
quote:
since there is not much of business logic, the business layer methods will simply act as stubs that will invoke the data access layer methods
Ooooops, I forgot, it's an n-tier example, even if one of the tiers doesn't do a goddamn thing of its own. I guess we need to use those GHz CPU cycles for something besides actual work.

Sorry for the cranky luddite voice, and for not contributing anything worthwhile to the debate, but I wish they'd stop preaching SQL-CLR with examples like these, and instead put out something that's actually new and improved.
Go to Top of Page

Sitka
Aged Yak Warrior

571 Posts

Posted - 2005-12-10 : 01:13:35
wow thanks so much for all this stuff. It will be reviewed multiple times to digest the points made. Just one thing for now; I think the article had a disclaimer about not being a good approach but it is a common way to present the ideas. I just get the impression that these kind of examples are met with nods from the OOP crowd and I hope to see what they see. Even if just to "know thy enemy"

"it's definitely useless and maybe harmful".
Go to Top of Page
   

- Advertisement -