473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Definition of "N-Tier"

I'm writing a winforms database application in C#. I've come across a lot of
stuff lately about "N-Tier" architecture.

Can anyone give me a simple explanation of N-Tier? The descriptions that
I've found online are chock full of lingo that I simply don't know. I need
the "N-Tier" for Dummies description. Talk to me like I'm in kindergarten.
Of course, I'm particularly interested in how N-Tier relates to creating a
winforms database application in C#.

As far as I understand "tiers", it appears that I'm currently using a 2-tier
architecture. What is N-Tier, and why is that more desirable? What is
"business logic"? Is that where you do your data validation?

(What I really can't wrap my brain around is how you could possibly remove
the data validation from the gui, particularly in a winforms application.)

Thanks!

Patrick
Nov 16 '05 #1
4 7002
"Patrick" <ne*******@devzoo.com> wrote in message
news:eD**************@TK2MSFTNGP11.phx.gbl...
I'm writing a winforms database application in C#. I've come across a lot of stuff lately about "N-Tier" architecture.

Can anyone give me a simple explanation of N-Tier? The descriptions that
I've found online are chock full of lingo that I simply don't know. I need
the "N-Tier" for Dummies description. Talk to me like I'm in kindergarten.
Of course, I'm particularly interested in how N-Tier relates to creating a
winforms database application in C#.

As far as I understand "tiers", it appears that I'm currently using a 2-tier architecture. What is N-Tier, and why is that more desirable? What is
"business logic"? Is that where you do your data validation?

(What I really can't wrap my brain around is how you could possibly remove
the data validation from the gui, particularly in a winforms application.)

Thanks!

Patrick


N-Tier is just fancy-talk for "multiple tiers" (the N may as well stand for
Nerd). For a good overview of designing N-Tier applications, check out the
following:

Application Architecture for .NET: Designing Applications and Services
(Chapter 2)

http://msdn.microsoft.com/library/de...AppArchCh2.asp

Erik
Nov 16 '05 #2
"Patrick" wrote...
What is N-Tier, and why is that more desirable?
It's the concept of creating more or less
*independent* layers of a system.

It comes from when the concept of client/server when the decisions were made
on where the actual "logic" of the application would be; on the client or on
the server, or perhaps separated on several servers?

The technique as such is not confined only to client/servers on a network,
but can also be applied to the architecture of a system on just one single
local machine, but still gives several advantages.

Following thoughts might help you understand the concept:

A) I have written a big application. How much of the
system do I have to change/affect if I only want to
change the User Interface?

B) I have written a big application. How much of the
system do I have to change/affect if I only want to
change how I store the data?

From these two thoughts we can see that there would in most cases be an
advantage to separate it into at least three layers (if you look around a
bit more, you'll see lots of examples with plenty more layers):

1. Presentation logic
2. Business logic
4. Data storage logic
What is "business logic"?
"Think away" how you display your data on the screen, and just see the
presentation layer as a "mediator" between the user and the *actual* logic
in the system. Do it also in the other direction, the data storage logic
only as a mediator of data to and from the database or whatever you use as
the storage of the data...

Simply put, what's left "in the middle" is the "business logic".

If your changes in A) above only affects the presentation logic, you have
sucessfully separated it from the business logic.

If your changes in B) above only affects the data storage logic, you have
sucessfully separated it from the business logic.
Is that where you do your data validation?


Not necessarily, that depends on what you actually mean with "data
validation"

Of course you should make some "data validation" in all three layers.

1. To guarantee that the presentation layer doesn't
send invalid data to the business logic.

2. To guarantee that the business layer works only
with valid data

3. To guarantee that the data layer is able to store
and retrieve data to to be valid in the business logic.

For starters, you can can try to create a winform application, but put as
much logic you can in a separate library. If you're able to use that library
in a web-application (e.g. ASP.NET) as well, *without* any changes, you have
succeded with separating the presentation layer from the rest.

The recollection above is somewhat simplified, but you asked for the
"dummies" version. ;-)

only my 2c.

// Bjorn A
Nov 16 '05 #3
Hi Patrick,

Thanks for having the courage to ask for a simple explanation. There are
too many acronymns and catch-phrases in this business.

Dividing an application into "tiers" is partly an attempt to increase code
reuse. It's a way of looking at application design from a higher level so
that it takes into account the long-term needs of the organization, not just
a particular application currently under development.

"Business Logic" is code that enforces business rules, such as a rule that
customers are only offered standard discounts of 2, 5 or 10 percent and that
discounts must be approved by a user with certain administrative rights.
The theory is that this rule is true throughout the organization, and so it
should not reside buried in the code of any specific application. Rather,
it should be in some central place and be called by any application that
needs to deal with discounts. So, an Accounts Receivable application and a
Sales Order application, for example, might both use this same business
rule.

So, business logic gets conceptually put in a "business tier" that all
applications share. The idea is to prevent constantly re-inventing the
wheel.

Two-tier apps are also known as client-server apps. They typically consist
of a data tier -- a back end database or a local database engine accessing
shared data on a server -- and the application itself, where everything else
lives.

Three-tier apps attempt to divorce the business logic from the application
and put it in a 3rd, business tier or layer. This might take the form of a
shared DLL used by many apps, or in a more pure form, it might consist of a
server application running in its own process space that responds to remote
calls from any other process. Typically the application talks to the
business layer, and the business layer passes requests to and from the data
layer (the database). Applications thus are written to the API of the
business layer, and only the business layer knows how to talk to the
back-end.

The other reason for adding more tiers is flexibility. If you uncouple
applications from the database itself, then it's easier to swap in different
back-ends, it's easier to support new versions of the back end, etc. The
application just keeps talking to the business layer and doesn't care.

One can have more than three tiers. For example it's fairly common to split
the business tier further into a business and a data access tier. Now you
have:

1) A specific back-end database
2) A data access layer that talks to that database and exposes a standard
API for accessing data
3) A business rules layer that talks to the data access layer
4) The presentation layer -- the UI itself, which talks to the business
rules layer.

Now you have decoupled even more and made it even easier to swap or scale up
different technologies.

Although 4-tier designs are very popular at this time, there are many ways
to design application layers, and so the general idea of splitting code into
layers has just been lumped under the term "n-tier" or "multi-tier" designs.

The downside of multi-layer designs is complexity. Obviously, it takes more
up-front effort (and, frankly, experience) to design a good n-tier
architecture and it's more of an enterprise-level undertaking. Over the
long haul it should pay off, but it is not as simple as just cranking out a
tightly-integrated application.

Another problem is that n-tier architecture is not a perfect metaphor.
There are places where it becomes unclear or impractical to maintain a sharp
division of labor between layers, or where you cannot completely do so. For
example, users expect immediate feedback in the UI if they enter something
incorrectly. A WinForms app would have the luxury of calling the business
layer in real-time to validate a field, but an ASP.NET app has the
fundamental problem that it is VERY disconnected from the server where the
central business layer would live.

So in an ASP.NET app you are forced to replicate a lot of business rules in
client-side JavaScript, and/or introduce a lot of extra post-back traffic
and page reloads in order to validate on the server.

The problem doesn't end there; for example, database stored procedures,
triggers, defaults and rules are often used both as a final data integrity
safety net and as a place to move some data manipulation and querying so
that it can run much faster by avoiding database server round-trips. Often,
such database server code replicates or even supplants logic in one or more
of the other layers.

N-Tier architecture is often touted as a silver bullet, like OO programming.
As Fred Brooks said many years ago, "There Is No Silver Bullet". However,
recognizing the need to centralize logic and improve code reuse as much as
is practicable is a generally Good Thing. If you are building software for
a company and want to take the long-range view, it's the way to go -- but it
will in the short run slow down and complicate your design, and maybe your
implementation at times as well.

Now ... a final note about removing data validation from the GUI. You don't
really remove it, you just don't (if possible) put the code that implements
it in the GUI. You make a call to some external process or library.
Otherwise it works the same. So as I pointed out above, it's actually
relatively EASY to divorce the code from the presentation layer in the case
of a WinForms app. Web apps are the *real* problem because of the
disconnected model of the web.

--Bob
"Patrick" <ne*******@devzoo.com> wrote in message
news:eD**************@TK2MSFTNGP11.phx.gbl...
I'm writing a winforms database application in C#. I've come across a lot of stuff lately about "N-Tier" architecture.

Can anyone give me a simple explanation of N-Tier? The descriptions that
I've found online are chock full of lingo that I simply don't know. I need
the "N-Tier" for Dummies description. Talk to me like I'm in kindergarten.
Of course, I'm particularly interested in how N-Tier relates to creating a
winforms database application in C#.

As far as I understand "tiers", it appears that I'm currently using a 2-tier architecture. What is N-Tier, and why is that more desirable? What is
"business logic"? Is that where you do your data validation?

(What I really can't wrap my brain around is how you could possibly remove
the data validation from the gui, particularly in a winforms application.)

Thanks!

Patrick

Nov 16 '05 #4
Having your database logic in each form and a dedicated db server elsewhere
is typically called Client/Server.

What if another customer wants the form to behave a bit differently? Do you
duplicate the database logic in the first form and make a note "when alter
this code, also update this other form....."? Nope :-)

N-Tier means to separate stuff, for example

1) Database (MSSQL etc)
2) Database logic for your app
3) Forms which use that database logic

You could have 1 on a server, or even 1 and 2 (if you use soap, remoting,
etc).

It's just good practise, you shouldn't mix your gui with your business
logic.
--
Pete
-------
http://www.DroopyEyes.com
Audio compression components, DIB Controls, FastStrings

http://www.HowToDoThings.com
Read or write articles on just about anything
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hartmut Sbosny | last post by:
Hello NG, I have a question. I have a header file with a function template and a fully specialized version of it, for instance //======== File "templ.hpp" ======== #include <iostream> // the...
10
by: Kobu | last post by:
My question is about the use and meaning of the terms "declaration" and "definition" as it pertains to the C language. I've read sources that mix the two up when talking about such things as...
8
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an...
1
by: CA | last post by:
I am having a problem getting a pointer to an existing running Excel process on a client machine. Here are some details: 1) I have tested out the code on the development machine and it works...
1
by: FirePhoenix | last post by:
please give me a demonstration. thanks --
5
by: han zhiyang | last post by:
Hi. I tried to design a custom web control which can flexibly and dynamicly let the control user ,for example the web page developer, customize its layout codes.This control derives from...
5
by: Fred Hebert | last post by:
I was thinking of switching to VS2005, so I sent off for and received a 120 evaluation kit. This version was supposed to be the same as the full version, but the key limits you to 120 days. I...
4
by: DR | last post by:
when i build someone's project, and right click a function "goto definition" is disabled. how to reconfigure a .net project to support "goto definition" when i right click on function calls?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.