Software developer

Tag Archives: Design & Patterns

Before my job as a software developer I was a software trainer. Being a software trainer I learned many things related to software engineering. But I knew very little about what is called multilayered applications. Why we use multilayered applications? Currently I know at least something about this fine and useful approach of software engineering. Blogging means to me is to share thing and thoughts. Today I want to share my thoughts and knowledge of multilayered architecture. For that I am going to develop a very small demo application. We all know about Northwnd database and I am going to develop a simple ASP.NET application using this Northwnd database Customers table. This is not only sharing of knowledge but also I want to learn more, so I will expect comments from you so that I can learn more on this particular topic

What is Multilayered Application?
Multilayered application is a particular type of software designing procedure in software engineering. In multilayered application we generally use three layers.

Data Access Layer (DAL)

Business Logic Layer (BLL)

User Interface Layer (UI)

This can be sub divided in more layers depending on your application requirements. We write code for data access in DAL. Business logic for our application in BLL and user interface in UI. The advantage is that if there is a change in application business logic or data access or UI logic then we have to recompile the particular component only. So we implement this architecture to make our code maintainable. One other point is that I am also defining an interface for every component through which the calling component can interact. That means I decouple the service contract and the actual implementation of that contract. The calling component that will use that component will actually use the service contract (the interface) not the actual implementation. That is the benefit of interface which is in the definition: Interface is a service contract between service provider and service consumer. The service consumer does not need to know about the implementation details. They will only dealing with the service contract which is defined in the interface.

Northwnd solution
I have created a solution for Northwnd. This solution has different components. Like POCO, DAL, BLL and UI.

The POCO Layer
POCO stands for Plain Old CLR Object. Here I have created a class which represents Customers table in our application. The concept is database has relational format and our application has object oriented format. So we create objects which actually map to database tables. This is the main concept of object relational map per (ORM). There are some example of ORM are LINQ TO SQL, Entity Framework, NHibernate etc. Though for this application I am not using any of this, I am writing data access code and mapping code manually. POCO is independent and plain object. For this we can use customer object from our DAL, BLL and UI in object oriented manner. We do not need to wary about how to map this object to database, which is having relational format. The customer class is defined in this POCO section of our solution. This class can be used from any other layer of this solution (DAL, BLL and UI).

The DAL Layer
Data access layer means, in this layer we write all the code which access the data from data source. We usually write the entire sql query or call store procedure from this layer.

In my application I write an another class called ‘Common’ in which I write all the common data access codes which can be used from the other classes in the DAL. This ‘Common’ class is only used inside the component, for that I declare this class as internal.

Another class in the DAL component is a static one and this is for extension method for ‘SqlDataReader’ class. Extension method is a procedure by which we can extents an existing type with non object oriented manner.

The BLL Layer
Every mid level to high level application has some business logic. In three layered architecture we writes business logic in BLL. In simple term, if data access layer has the responsibility to access the data source then data manipulation is done in business logic layer. In the case of data retrieval it makes the data ready for UI and in the case of insert, update and delete it makes the data ready for data access layer. So it actually stay just between the DAL and UI.

Though there is not much business logic for this demo application. But in real world there are usually much to do in BLL.

In the DAL and BLL I also do deterministic life cycle memory management.

The UI Layer
The main responsibility of UI is to render the result and the user interaction. I have implemented the validation logic in UI using ASP.NET validator control. There are two aspx pages. One to show the customer data in a ‘GridView’ control and another is edit, delete and insert data.

Rate this:

The word is ‘Polymorphism’. Greek origin. Meaning is different functions under same interface. For example, steering of a car. It may be manual steering or power steering. Their internal function is different. But for a driver steering interface is same. So that one driver can drive with two types of steering. There is no need to learn two different driving skills for two types of steering. So by polymorphism we can use our knowledge in different closely related implementations. Because for us the interface is same. We are familiar with that interface.

Polymorphism in software development

Just like our practical example polymorphism is applicable in our software development. Suppose we are developing software for client. After some times we also upgrade that software and add some new functionality in to that, as well as change some existing functionality. If we maintain the user interface as unchanged or familiar when we are upgrading the functionality, then it is better to use the new functionality for our client without any further training. Because for the client user interface is same, only under the same user interface the functionality has changed. This is polymorphism.

Polymorphism in Microsoft .NET Framework

In this post I will mention what are types of polymorphism and how we can implement polymorphism in our daily software development with Microsoft .NET Framework and C# programming language.

What are the types of polymorphism?

There are two types of polymorphism in .NET.

Static or compilation time polymorphism. (Early binding)

Dynamic or runtime polymorphism. (Late binding)

Static polymorphism

Static polymorphism means the polymorphism which is performed in compilation time. We can implement static polymorphism in three ways.

Method overloading.

Operator overloading.

Indexer overloading.

Method overloading

When we declare more than two methods in a class having the same name but different parameter list, then it is called method overloading. The methods are called overloaded methods. When we call the method, depending on the parameter list compiler makes a decision that which version of the overloaded method will be called.

We use operator to perform some operation on operands. There are many types of operator in programming language. Now the operands are primitive types. If we want to use the objects of our user defined class to be as operands of a particular operator, we have to overloads that particular operator in our user defined class.

Dynamic polymorphism means the polymorphism which is done not in compilation time but in runtime. There are four ways through which we can implement runtime polymorphism.

Method overriding.

Property overriding.

Polymorphism through Delegate.

Polymorphism through Interface.

Method and property overriding

Base class having general functionality, derive class means specific functionality. So base class having the methods and property which implement general functionality for all derive classes (some times they become abstract). Derive class may override that general functionality of base class to a more specific functionality. Then this is called overriding. Base class method or property is declared as ‘virtual’ and derive class method or property is declared as ‘override’. At runtime it is decided that what version (base or derive) will be called depending on the particular object.

Delegate means managed function pointer in .NET Framework. We can assign method reference in to a delegate, if the signature of the delegate and method are same. Through delegate we can create a polymorphic type of data structure.

Interface is a service contract between service provider and service consumer, irrespective of how the service will be provided. Many different classes can implement a single interface with different implementation.