n-layer approach

D

Dotnet

I want to so the "right thing". But first, I have a confession to make.
I've built a few ASP.NET sites now (Version 2.0), and they all work fine.
However, I have (and here's the confession) used the SqlDataSource in each
one of them.

I've read a number of blogs and articles that tell me this is just, well,
sinful. I have to adopt an n-layer/tier approach which makes use of a Data
Access Layer and a Business Logic Layer. I've researched this, and to me it
seems like a whole load of extra work for nothing.

The kind of sites I build are generally online magazines and web sites for
small to medium sized companies. I am not interested in getting involved in
"enterprise" applications, and I work on my own, so I don't have to worry
about cubicled specialists needing to work on bits of the web site in
isolation. Also, these sites will never change database, nor require a
windows form front-end. If any of them get 20,000 page impressions a month,
the owner will be well pleased. (Actually, one of them gets 1,000,000 a
year).

One of the sites was a migration from classic ASP, and resulted in a 90%
reduction in the number of lines of code. To me, this seems like a 90%
reduction in the likelihood of bugs, but then, I admit to missing the point.

If I were the cynical type, I might find myself thinking that the scorn
poured on the SqlDataSource in certain quarters is a result of fear. Using
it, I can build a site in a quarter of the time that it took me to build
something similar using classic ASP, and it's, ermmm... pretty simple to do.
I can see that it's simplicity will allow a whole load of people to build
sites commercially, who may not have found it so easy with scripting or
ASP.NET 1.x, which means the web development market will become more
competitive.

However, I don't consider myself cynical, and therefore must be missing
something important. Can anyone tell me what it is? Why should I be
adopting an n-layer approach?

Thanks

Mike
 
G

Guest

Hi

There are many reasons why you should use nTier
Applcations , But not all of them relate to "Enterprise Application"
and "Server Load" but to simple down to earth bug solving
and seperation of resources for code reuse.
lets go with these two examples:

1. example one is like the question why use Stored Procedured
or why even use Sql2005-Express and not access. and the answer is simple :
a) so I can devide my work so one person whould work and help me in the
design of the database without beeing dependent of him , b) if theres a bug
with the SP , we know that it's a SP problem with small or no effort.

2. Code reuse , you say you write many web sites , I guess that most of them
have "tblArticle" and "tblForum" and on and on, or in short , just like the
"BeerHouse" example has many usefull modules that you can be reuse . the same
is in your applications , meny modules you write so many times . and you know
by heart , wouldn't it be simpler to reuse the security component or the
forum component..... and many more .

.... are these two good enough examples of non enterprise related samples
which can drive you to re-think about all of this ?

-------------------------------------------
×× ×ª×©×•×‘×” זו עזרה לך, ×× × ×”×¦×‘×¢ "כן"

If my answer helped you please press "Yes" bellow

Adlai Maschiach
http://blogs.microsoft.co.il/blogs/adlaim/
 
D

Dotnet

Not enough reason for me to re-think yet. I use SPs exclusively, because I
don't like seeing all the SQL in my pages, and I work on my own. I shall
investigate the Beerhouse sample, but reuse surely means forcing the next
development to adopt/inherit the objects and properties of the previous one?
What if they are not compatible? Do I just keep adding methods and
properties to an object so that I can cover all eventualities? Or do I add
extra levels in by using a base object and then create my own that inherits
from it each time?

I don't use any code generation tools, and a significant part of any
development for me is creating all the stored procedures. n-layer won't help
me there, will it? All it does is give me a whole load of objects to code
too? I still don't get the point.

Are there server-load issues in relation to the SqlDataSource?
 
A

Aidy

The kind of sites I build are generally online magazines and web sites for
small to medium sized companies. I am not interested in getting involved
in "enterprise" applications, and I work on my own, so I don't have to
worry about cubicled specialists needing to work on bits of the web site
in isolation.

If you don't need an n-tier approach then don't use one. There is no point
using technology for technology's sake. The one thing I will say about the
SqlDataSource is that you're applications are not strongly typed, which is
one of the corners of .net development.
 
P

Peter Bradley

Aidy said:
If you don't need an n-tier approach then don't use one. There is no
point using technology for technology's sake. The one thing I will say
about the SqlDataSource is that you're applications are not strongly
typed, which is one of the corners of .net development.
I agree.

As long as your applications don't deal with sensitive data, there's no
reason why you should get too sophisticated. There is no, "One size fits
all" in application development.


Peter
 
D

Dotnet

Aidy said:
If you don't need an n-tier approach then don't use one. There is no
point using technology for technology's sake. The one thing I will say
about the SqlDataSource is that you're applications are not strongly
typed, which is one of the corners of .net development.

I should point out that one of my faults/problems is a lack of OOP
knowledge. Is it relatively easy for you to explain what the practical
implications of my applications not being strongly typed are (or point me to
references that will do so), and why did Microsoft introduce a component
that would allow (encourage) this if it is serious?

Thanks
Mike
 
A

Aidy

why did Microsoft introduce a component that would allow (encourage) this
if it is serious?

I could do a website and not right a single line of code. I can drag
connections, tables etc on the form and have wizards do all my code. If you
don't want to learn how to code it is better than nothing....but the
resultant application won't be very robust or scalable. You can use
SqlDataSources to cut out a lot of the actual coding, but that doesn't mean
your solution is the "best" it can be. MS have just given you a range of
tools to use and you decide which one is best for you. If binding typeless
data direct to your controls is fine for you then fair enough. For people
who want strongly typed data it isn't fine.
 
P

Peter Bradley

Heh! Strong typing isn't just an OOP thing. C is strongly typed.

What is your programming background? It might give some hints as to what
you might need to know. Generally, however, strong typing is used to ensure
that programmers only put into an object, what that object is supposed to
hold (e.g. you can't store a float in an int variable - unless the language
provides some form of implicit cast). The idea is that this cuts out a lot
of mistakes that would otherwise be made, by catching them at compile time.


Peter
 
D

Dotnet

VBScript with classic ASP. All variants....

Peter Bradley said:
Heh! Strong typing isn't just an OOP thing. C is strongly typed.

What is your programming background? It might give some hints as to what
you might need to know. Generally, however, strong typing is used to
ensure that programmers only put into an object, what that object is
supposed to hold (e.g. you can't store a float in an int variable - unless
the language provides some form of implicit cast). The idea is that this
cuts out a lot of mistakes that would otherwise be made, by catching them
at compile time.


Peter
 
A

Aidy

All variants....

Explains it all :D

What you're basically doing is doing ASP.net the ASP way. Quite common
really, but not the best way.
 
C

cowznofsky

Hi

There are many reasons why you should use nTier
Applcations , But not all of them relate to "Enterprise Application"
and "Server Load" but to simple down to earth bug solving
and seperation of resources for code reuse.
lets go with these two examples:

1. example one is like the question why use Stored Procedured
or why even use Sql2005-Express and not access. and the answer is simple :
a) so I can devide my work so one person whould work and help me in the
design of the database without beeing dependent of him , b) if theres a bug
with the SP , we know that it's a SP problem with small or no effort.

2. Code reuse , you say you write many web sites , I guess that most of them
have "tblArticle" and "tblForum" and on and on, or in short , just like the
"BeerHouse" example has many usefull modules that you can be reuse . the same
is in your applications , meny modules you write so many times . and you know
by heart , wouldn't it be simpler to reuse the security component or the
forum component..... and many more .

... are these two good enough examples of non enterprise related samples
which can drive you to re-think about all of this ?

-------------------------------------------
×× ×ª×©×•×‘×” זו עזרה לך, ×× × ×”×¦×‘×¢ "כן"

If my answer helped you please press "Yes" bellow

Adlai Maschiachhttp://blogs.microsoft.co.il/blogs/adlaim/

Just to add to the confusion, I recently attended an MS workshop on
Windows Forms Technologies. There is nothing at all mentioned about
an n-layer approach. The use of controls such as the SQLDataSource is
noted as 'Best Practice'.
I can't understand this at all, since this is in direct contradiction
to the multi-tiered approach that MS has been pushing in other media
for years.

These controls are often used in MS presentations: "Look, I just
created an application in 10 seconds!". These controls also find
their way into the books that are written to coincide with new
releases. The result is a lot of wasted time on the part of
developers who try these things and then realize later that they would
have been better off if they had used code rather than these data
access controls.

Some of the "scorn poured on the SQLDataSource", is no doubt from
developers who have been burned before.
 
D

Dotnet

Aidy said:
Explains it all :D

What you're basically doing is doing ASP.net the ASP way. Quite common
really, but not the best way.

And that says it all. I am still none the wiser for your contribution.
 
S

sloan

Here is another way to phrase it.

RAPID DEVELOPMENT is not the same as GOOD and Maintainable Development.

The little tools, SqlDataSource , etc ,etc are for rapid development.

Good development is something else altogether.

The layers help make your code reusable and maintainable.

And you have options for future scaleability.


The cost of software isn't in the devlopment, its in the maintenance.

Layered software really helps with the debugging process.




6/5/2006
Custom Objects and Tiered Development II // 2.0

5/24/2006
Custom Objects/Collections and Tiered Development

http://sholliday.spaces.live.com/blog/
 
P

Peter Bradley

<rant>
Because they're selling to the PHBs who think that coding, "Is all
drag-and-drop these days". People like you, on the other hand, pick up that
what they're saying is self-contradictory nonsense.

Be-suited CTOs are apparently incapable of realising that solving difficult
problems is difficult. No amount of drag-and-drop can make it easy. But
all they can see is "applications ready for shipment in a matter of hours".
The fact that these applications are barely functional, flakey, insecure and
bloated - never mind the fact that much of the code is now hidden from
view - hardly makes it onto their radar.

It's like the use of tools to write HTML. Tools write dreadful HTML (never
mind XHTML). Every one of them. Including Dreamweaver. But will your boss
believe you that it's easier to hand code your pages? Oh dear no! So you
have to use the idiot tool he bought licenses for without consulting the
people who do the work, and then spend days de-moronising HTML pages. Then
he wonders why the project's late.

They swallow Microsoft's latest Kool-Aid and the poor practitioners are left
to pick up the pieces. The only winner in all this is, guess who? Correct.
Microsoft, who've sold another vapour-ware license for many times its worth.
</rant>

Peter

On Mar 5, 3:15 am, Adlai Maschiach

Just to add to the confusion, I recently attended an MS workshop on
Windows Forms Technologies. There is nothing at all mentioned about
an n-layer approach. The use of controls such as the SQLDataSource is
noted as 'Best Practice'.
I can't understand this at all, since this is in direct contradiction
to the multi-tiered approach that MS has been pushing in other media
for years.

These controls are often used in MS presentations: "Look, I just
created an application in 10 seconds!". These controls also find
their way into the books that are written to coincide with new
releases. The result is a lot of wasted time on the part of
developers who try these things and then realize later that they would
have been better off if they had used code rather than these data
access controls.

Some of the "scorn poured on the SQLDataSource", is no doubt from
developers who have been burned before.
 
P

Peter Bradley

I think what he's saying (although not very kindly IMHO) is that you could
do with spending some time looking at some of the theories behind
programming in general, and good programming practices in particular. This
is not knowledge that one finds, usually, amongst people with your
programming background. In fact, many people would argue that the scripting
languages you mention mitigate against good programming practice.

This group can't supply you with a background knowledge of programming
theory and practice. You need to sit down with a few good books for that.
This one might do for a start:

http://www.compman.co.uk/scripts/browse.asp?ref=783974

(Since you're interested in an OO language, you'd might as well learn the
theory behind it)

Once you've got some basic background, you might like to look at books on
patterns and practices. Like this for example:

http://www.compman.co.uk/scripts/browse.asp?ref=801797

(Since you're intersted in an MS product, you'd might as well read MS' book)

Remember that most of us came by this knowledge through hard work. We're
happy to pass on the hints and tips that we picked up along the way, but a
newsgroup is not the place for a tutorial. For that you must either read
books or join a course. This is not trying to be unkind. It's just that
without a basic level of background knowledge, you aren't going to
understand what we say. We need to have a common vocabulary with you for us
to communicate and for you to understand.

What I'm suggesting is that you need to spend some time learning that
vocabulary. I'm sure you'll find it rewarding. I did.

Best of luck and HTH


Peter
 
D

Dotnet

Thank you Peter.

Incidentally, I have had no formal training in any kind of programming. As I
said in my OP - I want to "do the right thing". I learnt ASP with VBScript
in my own time through hard work, and became very conscious of doing it as
well as possible. I'm going through the same process with ASP.NET. There
is so much to learn, and as cowznofsky pointed out, so much contradictory
stuff, I thought I'd come here and get a little help on focusing my
attention in the right areas, and trying to identify the red herrings.

Mike
 
P

Peter Bradley

Best of luck, Mike. I hope the references I gave give you a start. There's
also a wealth of tutorial material on the net - but it's of varying quality,
so I'd not rely on it until you have enough knowledge to judge.

I came into IT very late in life, and one thing I did was to study night
school and part-time/distance learning classes. I finished up, somehow,
with an MSc in IT at Liverpool University. If you're in the UK (or even if
you're not, come to think of it), you might look at UK Open University
courses. They do some good stuff on OOA/D/P at both undergraduate and
post-graduate level. It's Java or Smalltalk based, depending on the course,
but once you have that background, you'll find C# comes naturally. Java,
especially, as it's very close to C#. You can just take whatever modules
you like with the OU. You don't have to study for a degree.

Remember that there's more to programming than just "getting something
working". It's a craft: a skill. Good programmers take a pride in a job
well done: in being able to look at some code and think, "Not many people
could have done that any better than I have". They worry about
architecture, good design, security, reusability, performance and many other
things (like whether to use vi or emacs :)).

Post again when you need some specific help. The problem with your OP was
that an answer requires that you understand a fair bit about application
architecture, design patterns and program security. Until you have that,
it's hard to answer your query without seeming either rude or patronising.
But you seem to be a determined guy. You'll probably come back and put our
problems right.

Cheers


Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top