Today we are going to discuss the architecture that we follow generally to develop an ASP.NET application. Most of you have worked with ASP.NET applications and you might have already developed so many websites, but have you ever thought of any standard way that can be followed to develop an application in ASP.NET.
There are many standard ways that we follow today. Each company or an organization will follow their own coding standards, but most of them have common ways of developing an application.
Now I am going to show you the standard that we follow in our applications. I don't say this is the only way that can be followed. But this is definitely a good way to start with an ASP.NET application.
The approach we are going to see now is three layered approach in which we have three layers
- Presentation Layer
- Business Logic Layer
- Data Layer
In presentation layer, we need to put all the forms or user interface related information . This layer can consist of code related to events that we handle for the user actions. Also the methods that we use for the actions taken by the users. We can say this is the user interface layer where all the user actions have to be handled here. This layer will interact with the Business Logic Layer to get the information from the database. Also the presentation layer depends on Business Logic Layer to interact with the Data Access Layer. This layer can't directly interact with the Data Logic Layer (it doesn't mean that we can't call the methods in Data Access Layer). Syntatically we can directly call the methods of Data Access Layer from the presentation layer, but it violates our principle of Layered Architecture.
Business Logic Layer:
In Business Logic Layer, we write the classes related to a particular project. This means that it includes methods which actually implement the logic required for a business (or an application project). This layer can interact with the Data Access Layer to get the data from the database or to connect to database, insert data into the database. Also this layer interacts with the Presentation Layer that we already discussed in the previous section.
important: Creating these layers doesn't mean that we are following the standards. We need to interact from Presentation Layer <===> Business Layer <===> Data Access Layer. So while interacting we need to share the data/information between the layers. This can be done in many ways.
Most of the developers follow the common way of sending parameters. But C#.NET provides us the best way to do this. That is Properties.
Properties can be created for each field in the back-end (database tables) and make them available to presentation later and data access layer. These properties have to be declared in the Business Logic Layer. Because we can modify / type cast the values according to your own business logic. Then we can directly pass the object of the Business class to Data Layer to make them available in the Data Access Layer.
Data Access Layer:
This layer purely for preparing the ADO.NET objects and the connection related methods and classes. Here we have to prepare the Sqlcommand,Sqlconnection,Sqldatareader,Sqldataadapter etc objects and open the connection, call the required method to interact with the database and get the information from the database then return that to the Business Logic Layer. This will in turn return the data to the Presentation Layer.
Have fun programming :)