Design Patterns Its Importance and TypesAssume that you have received a new requirement from the Client. You performed analysis of it and you know what has to be done to fulfill the requirement and how to do it as well. Now what will you do? If you are going to start right away with the code then it will be an unplanned approach.
Though you
might finish and deliver the code, your code might not be maintainable
and reusable. Hence you have to follow certain architecture that is proven
to be reusable. Such architecture is presented using design patterns.
Design patterns do not right away give you the solution for the problem.
If you know the solution, design patterns will help you in presenting
the solution in better way such that your code will be reusable as well
as maintainable.
In your web application, you will have user interface screen that is shown to the User. User enters certain information in the screen. Based on this information, you perform certain computations and display output to the User. How do you code it? Do you have both the UI display related code and the computation code in the same page? Then you are not writing a worthy code. When you want to perform a change related to either UI display or its computational logic, you are going to disturb the whole page. This is not a desirable approach. You have to split the UI content creation from that of the action/computation required to process them. This is done in MVC Pattern using three components: View
- User Interface related code will reside here. View components will be
saved as *.aspx, *.ascx and master pages. For better understanding consider the login screen. For implementing login screen for your application, you should have three pages in your application code pertaining to each one of them: View
Include necessary textboxes and buttons to display login screen
to the User Using MVC you can clearly distinguished your task into components. Hence change required in one component doesnt have any impact on the other components. Therefore maintenance will be easier and reusability will be high. Design Patterns are classified into three categories which are mentioned below: Creational
Design Patterns Creational design patterns help you in creating instances of classes. Creation of instances might vary based upon your requirement and at times you might really not know which instance has to be created (during compile time). This will be finalized only at run time rather than at compile time. It is always desirable to move such logic related to instance creation into a separate class called creator class. Structural Design Patterns involve in grouping of classes and objects to form larger structures. Objects are generally grouped using object composition or at times, objects can include other objects within it. By grouping objects, you can easily establish communication across them. Behavioral Design Patterns concentrate on establishing communication across objects. There are 23 core design patterns based on which many other customized patterns have been evolved. These patterns also fall under the design pattern classification. Each of them fit either into creational or structural or behavioral patterns based on their functionality. What are these 23 patterns and to which category of design patterns do they belong to? This is answered using the classification hierarchy shown below:
|