473,651 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7017
"Patrick" <ne*******@devz oo.com> wrote in message
news:eD******** ******@TK2MSFTN GP11.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*******@devz oo.com> wrote in message
news:eD******** ******@TK2MSFTN GP11.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
6189
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 general function template... template <class T>
10
20858
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 setting aside storage for an object, defining/declaring a struct, parts of a function, referencing an external variable in another module. sourcefile1.c ============== extern long globalfoo; /* declaration? */
8
3367
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 actual program. To me "scope" of the name of a function or object are the general rules for the areas of a program that can through a declaration, have "visibility."
1
2519
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 fine. (Excel XP) 2) The code works fine on a machine in our offices with Excel 2000. 3) On the client machine (with Excel 2000), the code does not work. I wrote some diagnostic tests to further try and see what was going on
1
2995
by: FirePhoenix | last post by:
please give me a demonstration. thanks --
5
4235
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 System.Web.UI.Control,and for my purpose,I define a delegate property in the control's class definition, so control user can define his(or her) method out of the class definition and add his(or her) method to the delegate chain. I also override the Render...
5
5922
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 installed it and began learning how to use it. I built several small C# test apps that use common classes in a dll that I also wrote. When I right click on a class that was defined in the dll and select "go to definition" it would open the source...
4
1467
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
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8697
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8579
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7297
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.