Design Patterns – Its Importance and Types

Assume 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.

Secondly, design patterns help you in sticking to the object oriented principles. For example, you require multiple entities to be part of your program. You have to ensure that each entity is independent of each other, at the same time communication must exist between these entities. How do you do it? You can achieve it using design patterns.

The design pattern which is most frequently used and assumed to be known to all programmers is the MVC Pattern. MVC stands for Model View Controller. This is the basic framework upon which all other day to day frameworks like STRUTS are built. MVC Framework can be pictorially represented as shown below:

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.
• Model - Computational logic will be performed here. Model components are recorded as classes in the folder “App_Code”
• Controller - Acts as a mediator between view and the model to establish interaction between them. Controller component is saved as *.cs file.

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
• Model – Validate login credentials entered by the User
• Controller – When User enters login credentials and clicks on Submit, pass the control to Model for validating the data entered. Send the response from the model to the View and display the next page of the application if the User is valid. If not, prompt error message

Using MVC you can clearly distinguished your task into components. Hence change required in one component doesn’t 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
• Structural Design Patterns
• Behavioral 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:

This diagram includes only the pattern names. You should spare time to study and analyze each of these patterns. After which you can incorporate suitable design patterns in your code.

| Project Management Controlling and Planning | Project Management Plan Proposal Preparation | Project Management Problem Solving Skills and Techniques | Project Management Scheduling Tools and Variance | Project Management Team Roles and Selection | Project Manager Qualities and Qualification | Project Manager Skills and Techniques | Project Report Format Samples and Templates |

“Amazon and the Amazon logo are trademarks of, Inc. or its affiliates.”

| Privacy Policy for | Disclosure | Contact |

Copyright - © 2004 - 2024 - All Rights Reserved.