C# .NET - Windows Application - Asked By suresh kotte on 19-Sep-11 07:08 AM

Hai All,

What is a 3 Tier and N Tier Architecture ? And We can software Development In Which mostly is Used ?


Thanks in Advance
k.Suresh
dipa ahuja replied to suresh kotte on 19-Sep-11 07:12 AM
Its depends on the size of your software.. if you software is small then you should use 3 tire or if its very large contain complex programming , tables , relationship then you should go for n-tire
Reena Jain replied to suresh kotte on 19-Sep-11 07:13 AM
Hi,


3-Tier architecture generally contains UI or Presentation Layer, Business Access Layer (BAL) or Business Logic Layer and Data Access Layer (DAL).

Presentation Layer (UI)
Presentation layer cotains pages like .aspx or windows form where data is presented to the user or input is taken from the user.

Business Access Layer (BAL) or Business Logic Layer
BAL contains business logic, validations or calculations related with the data, if needed. I will call it Business Access Layer in my demo.

Data Access Layer (DAL)
DAL contains methods that helps business layer to connect the data and perform required action, might be returning data or manipulating data (insert, update, delete etc). For this demo application, I have taken a very simple example. I am assuming that I have to play with record of persons (FirstName, LastName, Age) and I will refer only these data through out this article.

here is the link to understand it more
http://www.codeproject.com/KB/architecture/three_tier_architecture.aspx
http://www.dotnetfunda.com/articles/article71.aspx
http://www.c-sharpcorner.com/uploadfile/paulabraham/building3tierapppa11282005053625am/building3tierapppa.aspx

hope this will help you
Suchit shah replied to suresh kotte on 19-Sep-11 07:53 AM

The three tier software architecture emerged in the 1990s to overcome the limitations of the two tier architecture. There are three layers when we talk about three tier architecture:-
User Interface (Client) :- This is mostly the windows user interface or the Web interface but this has only the UI part.
 Mid layer: - Middle tier provides process management where business logic and rules are executed and can accommodate hundreds of users (as compared to only 100 users with the two tier architecture) by providing functions such as queuing, application execution, and database staging.
Data Access Layer: - This is also called by the famous acronym "DAL" component. It has mainly the SQL statement which do the database operation part of the job.
The three tier architecture is used when an effective distributed client/server design is needed that provides (when compared to the two tier) increased performance, flexibility, maintainability, reusability, and scalability, while hiding the complexity of distributed processing from the user.


N-tier and 3-tier are architectural deployment styles that describe the separation of functionality into segments in much the same way as the layered style, but with each segment being a tier that can be located on a physically separate computer. They evolved through the component-oriented approach, generally using platform specific methods for communication instead of a message-based approach.

N-tier application architecture is characterized by the functional decomposition of applications, service components, and their distributed deployment, providing improved scalability, availability, manageability, and resource utilization. Each tier is completely independent from all other tiers, except for those immediately above and below it. The nth tier only has to know how to handle a request from the n+1th tier, how to forward that request on to the n-1th tier (if there is one), and how to handle the results of the request. Communication between tiers is typically asynchronous in order to support better scalability.

N-tier architectures usually have at least three separate logical parts, each located on a separate physical server. Each part is responsible for specific functionality. When using a layered design approach, a layer is deployed on a tier if more than one service or application is dependent on the functionality exposed by the layer.

An example of the N-tier/3-tier architectural style is a typical financial Web application where security is important. The business layer must be deployed behind a firewall, which forces the deployment of the presentation layer on a separate tier in the perimeter network. Another example is a typical rich client connected application, where the presentation layer is deployed on client machines and the business layer and data access layer are deployed on one or more server tiers.

The main benefits of the N-tier/3-tier architectural style are:

  • Maintainability. Because each tier is independent of the other tiers, updates or changes can be carried out without affecting the application as a whole.
  • Scalability. Because tiers are based on the deployment of layers, scaling out an application is reasonably straightforward.
  • Flexibility. Because each tier can be managed or scaled independently, flexibility is increased.
  • Availability. Applications can exploit the modular architecture of enabling systems using easily scalable components, which increases availability.

Consider either the N-tier or the 3-tier architectural style if the processing requirements of the layers in the application differ such that processing in one layer could absorb sufficient resources to slow the processing in other layers, or if the security requirements of the layers in the application differ. For example, the presentation layer should not store sensitive data, while this may be stored in the business and data layers. The N-tier or the 3-tier architectural style is also appropriate if you want to be able to share business logic between applications, and you have sufficient hardware to allocate the required number of servers to each tier.

Consider using just three tiers if you are developing an intranet application where all servers are located within the private network; or an Internet application where security requirements do not restrict the deployment of business logic on the public facing Web or application server. Consider using more than three tiers if security requirements dictate that business logic cannot be deployed to the perimeter network, or the application makes heavy use of resources and you want to offload that functionality to another server




Three-Tier Application Using an XML Web Service

Another design option is to use an XML Web service to separate the database's access to another component that returns the data to the front-end application. Figure 2 illustrates this design option.

For more information on developing three-tier applications using XML Web services, use the MSDN search engine.

Figure 2. Use an XML Web service to separate the database layer from the front-end code

When To Use This Technique

A three-tier application using an XML Web service is appropriate for either a Web-based or Microsoft Windows® application. This technique comes in handy when you need the richness of a desktop application, but users connect to it from many different locations and access the data across an HTTP interface.

Typical Implementation Options

You will most likely use the following development techniques to create a three-tiered/XML Web service application:

  • All SQL resides within the XML Web service. Datasets are built on the server and returned as an XML stream to the client where they can be rebuilt into datasets.
  • Datasets returned from the XML Web service can be bound directly to the controls on the forms.
  • Datasets returned from the XML Web service can be used to manually load data into the various controls on the forms.
  • All business rules are coded directly on the forms.

Advantages

A three-tier application using an XML Web service has the following advantages:

  • Development can be quick and easy because you can use data binding to connect an ADO.NET dataset directly to many of the controls used to build the user interface. This helps you get the basic functions of an application up and running quickly.
  • Users can run your application from anywhere they have connectivity to the Internet (or intranet).
  • Database access is separated to its own component so the front-end code does not have SQL embedded in it.
  • Connection information is maintained only on the XML Web service, again minimizing client machine maintenance.
  • The database access layer can be updated in a central location. There is no need to redistribute components to the client if you make a simple code change to this layer.

Disadvantages

The disadvantages to this design are essentially the same as for a typical two-tier application, since you have not separated the business rules, just the data layer. You also have not abstracted the column names in the tables into a class—something you will learn about in the next section.

  • All business rules are contained in the front-end code. As a result, if you need to change a business rule, all clients must be updated. Unless you have an automated update approach, this can be a maintenance nightmare. Of course, if you use SQL Server, you can put some business rules into stored procedures to decrease maintenance time and costs.
  • All field names are hard-coded into either the source code or control properties. If you change a field name, you have to find and replace every occurrence in your application. When data binding is involved, you also have to check all forms and change properties.
  • Performance across an HTTP interface is slower than a direct database connection.
  • If the user does not have Internet (or intranet) access, the application is unusable.

Three-Tier Application Using .NET Remoting

This type of application architecture is almost exactly the same as the three-tier application using an XML Web service. The only difference is that you use .NET Remoting instead of an XML Web service to wrap up the data access layer. Figure 3 illustrates this design option.

For more information on .NET Remoting, see the other articles in this series or use the MSDN search engine.

Figure 3. Working within a LAN environment, you can use .NET Remoting to wrap up the data access layer

When to Use the Three-Tier .NET Remoting Technique

A three-tier application using .NET Remoting is appropriate for an application 'that must be distributed between computers on a LAN. This may be for business reasons or because the cost of the work involved justifies the cost of the network call.

Typical Implementation Options

You will most likely use the following development techniques to create this type of application.

  • All SQL resides within the component called through the Remoting service. Datasets are built on the server and returned as an XML stream to the client where they can be re-built into datasets.
  • Datasets returned from the Remoting component are bound directly to the controls on your forms.
  • Datasets returned from the Remoting component are used to load data manually into the different controls on your forms.
  • All business rules are coded directly on the forms.

Advantages

A three-tier application using .NET Remoting has the same basic advantages as a three-tier application using an XML Web service.

  • Three-tiered applications are quick and easy to program because you can use data binding to connect an ADO.NET dataset directly to many of the controls that you use to build the user interface. This helps you get the basic functionality of an application up and running quickly.
  • Users can run this application from anywhere they have connectivity to the LAN or WAN.
  • Database access is separated to another component so the front-end code does not have any SQL embedded in it.
  • The database access layer can be updated in a central location. There is no need to redistribute components to the client if you make a simple code change in this component.
    Note This advantage is true for all n-tier architectures.

Disadvantages

The disadvantages of this type of three-tier design are the same as those described when using an XML Web service.

  • All business rules are contained in the front-end code. As a result, if you need to change a business rule, all clients must be updated. Unless you have an automated update approach, this can be a maintenance nightmare. Of course, if you use SQL Server, you can put some business rules into stored procedures to decrease maintenance time and costs.
  • All field names are hard-coded into either the source code or control properties. If you change a field name, you have to find and replace every occurrence in your application. When data binding is involved, you also have to check all forms and change properties.
  • Data transfer from one component to another across a network is slower than a direct database connection. .NET Remoting in an intranet scenario can perform better than an XML Web service. You are less likely to use .NET Remoting in an Internet scenario.
  • Setting up this type of application is a little more complicated than either a two-tier application, or one that uses an XML Web service.

Logical N-Tier Applications

The best approach to building an application using .NET is to separate all logical processes into discrete classes. In a typical business application, this generally involves a business rule component, a data layer component, and the front-end code that uses these components. Figure 4 illustrates this approach.

For more information on designing an n-tier application, see the other articles in this series or use the MSDN search engine.

Figure 4. Break up business processes into separate classes to make your application easier to create and maintain

When to Use an N-Tier Architecture

Using a logical n-tier development strategy is appropriate for all types of applications. It works equally well in small, medium, and large applications, and with both desktop and Web applications.

Typical Implementation Options

You will most likely use the following development techniques to create this type of application:

  • Create the front-end user interface using either Windows Forms or Web Forms.
  • Create the business rule component as a separate Class Library project.
  • Create a data layer component as a separate Class Library project. This data layer uses classes to wrap up access to each table. Typed datasets should be used; they provide the flexibility of the dataset class and strong typing for each column in the tables.

Advantages

A logical n-tier application has the following advantages:

  • Centralizes business rules into a component that is easy to create, use, and re-use. This makes development and maintenance easier.
  • Provides a high-level language in which to develop business rules, as opposed to using stored procedures and limited SQL language for business rule checks.
  • Centralizes the data access into a component. This means less repeated code throughout your application; each form that needs to access a specific table always uses the same component.
  • If you use typed datasets, you get the benefit of looking up column names using IntelliSense instead of having to remember them.
  • Centralized data access routines help with maintenance, since changes to any data access routine need be made only once.
  • Provides the flexibility to separate components onto different physical machines at any time. This helps with scalability and better centralization of code.

Disadvantages

A logical n-tier application has only two significant disadvantages:

  • Development takes a little longer because you must build separate components.
  • There are a few more components to track. This makes this development method a little more complicated to understand for new programmers.

N-Tier Application Using an XML Web Service

Figure 5 shows an example of how you might take a logical n-tier application design and split it across multiple machines. In this diagram, you can see that an XML Web service is used to access the data layer. The typed dataset is returned across the HTTP layer to the business rule layer. The client application can then consume the dataset for the user interface presentation of the data.

Figure 5. Separate your business processes onto separate machines to help with deployment and maintenance

When to Use This Technique

The n-tier XML Web service type of application design is appropriate when you need the richness of a desktop application, but users may be connecting from many remote locations and need to get the data across an HTTP interface. Keeping the business rules on the client side helps with network traffic, but can impose some maintenance update hassles if the rules change frequently. Because .NET is able to copy over new DLLs without registration, these issues are not as severe as they used to be in earlier technologies.

This scenario can also be useful for Web-based applications where the data might be provided by one Web server, but displayed by another Web application on another Web server.

Typical Implementation Options

You will most likely use the following development techniques to create this type of application. 'These techniques are the same as those of the logical n-tier application.

  • Create the front-end user interface using either Windows Forms or Web Forms.
  • Create the business rule component as a separate Class Library project.
  • Create a data layer component as a separate Class Library project. This data layer uses classes to wrap up access to each table. Typed datasets should be used; they provide the flexibility of the dataset class and strong typing for each column in the tables.

Advantages

An n-tier application using an XML Web service has several advantages, many of which are' the same as those of the logical n-tier application.

  • Centralizes business rules into a component that is easy to create, use, and re-use. This makes development and maintenance easier.
  • Provides a high-level language in which to develop business rules, as opposed to using stored procedures and limited SQL language for business rule checks.
  • Centralizes the data access into a component. This means less repeated code throughout your application; each form that needs to access a specific table always uses the same component.
  • If you use typed datasets, you get the benefit of looking up column names using IntelliSense instead of having to remember them.
  • Centralized data access routines help with maintenance, since changes to any data access routine need be made only once.
  • Provides the flexibility to separate components onto different physical machines at any time. This helps with scalability and better centralization of code.
  • Added benefit: Centralized data access layer.
  • Added benefit: Application scalability—you can add a Web farm to handle heavy loads of user requests to the database.
  • Added benefit: Users can connect over the Internet and still access the data from a desktop or Web-based application.

Disadvantages

The n-tier application using an XML Web service development method has a few disadvantages. Most of these disadvantages are the same as those described when using the logical n-tier application development scenario.

  • Development takes a little longer because you must build separate components.
  • There are a few more components to track. This makes this development method a little more complicated to understand for new programmers.
  • If the XML Web service is not functioning, the application is unusable.

Other N-Tier Application Techniques

Of course, there are many different techniques you could use to create an n-tier application. For example, you could use .NET Remoting to communicate from the client tier to the business rule tier, as illustrated in Figure 6.

Figure 6. You can use a combination of .NET Remoting and XML Web services to give your application the best scalability and maintainability

There are a variety of ways you can configure an n-tier application once you have developed it using n-tier techniques. You can combine any of the methods available in .NET to separate the tiers of an application.

Riley K replied to suresh kotte on 19-Sep-11 12:37 PM

n-tier implies n is any number - when n=3 then it is the same as n-tier.

The usual definition of 3-tier is presentation, logic & data (in any order), and yes, SOA can confuse the neophyte because sometimes it sits in the data tier, sometimes the logic tier and sometimes both logic & data tiers.

The whole subject is...subjective. If you need some tiers then call it n-tier - if you know that n=7 then call it 7-tier, or n-tier

You can refer this link from MSDN for more detail

http://msdn.microsoft.com/en-us/library/ms973829.aspx

Cheers