A Recall of Design Patterns



What is a Pattern?

A pattern is a reusable solution that can be applied to commonly occurring problems in software. In other words, patterns are as templates for how we solve problems that occurred during software development.
Basically, design patterns have three main benefits.

1.      Design patterns helps us in preventing minor issues that can cause major problems in the application development process. Because when code is built on proven patterns, we can afford to spend less time worrying about the structure of our code and more time focusing on the quality of our overall solution. Patterns can encourage us to code in a more structured and organized fashion avoiding the need to refactor it for cleanliness purposes in the future.
2.      Patterns can provide generalized solutions which are documented in a fashion that doesn't require them to be tied to a specific problem. This generalized approach means that regardless of the application and the programming language we are working with, design patterns can be applied to improve the structure of our code.
3.      Certain patterns can actually decrease the overall file-size of our code by avoiding repetition. By encouraging developers to look more closely at their solutions for areas where instant reductions in repetition can be made, e.g. reducing the number of functions performing similar processes in favor of a single generalized function, the overall size of our codebase can be decreased.

Remember, Patterns are not an exact solution. Patterns merely provide a solution scheme.Patterns support the software designer to solve the problems in software designing.

We already use patterns everyday

We use design patterns so commonly. Now a days, jQuery is a major part of web development. Suppose, we need to find out all elements of a DOM object having a class “Mandatory”. To tackle this situation, we have to use some native browser feature such as querySelectorAll() or getElementsByClassName() or write some code to fetch out that elements. Due to jQuery, we don’t need to worry as jQuery abstracted away for us using the Façade pattern. So for this situation we just use $(.Mandatory) to select all DOM elements having class “Mandatory”.
We're probably all also familiar with jQuery's $("selector"). This is significantly more easy to use for selecting HTML elements on a page versus having to manually handle opt for getElementById(), getElementsByClassName(), getElementByTagName and so on.

Categories Of Design Pattern


Each design pattern focuses on a particular object-oriented design problem or issue. It describes when it applies, whether or not it can be applied in view of other design constraints, and the consequences and trade-offs of its use. Design patterns can be broken down into a number of different categories. Mainly, design patterns are fallen into three categories:

Creational Design Patterns

As the name suggests, creational design patterns focus on handling object creation mechanisms where objects are created in a manner suitable for the situation we're are working in. The basic approach to object creation might otherwise lead to added complexity in a project whilst these patterns aim to solve this problem by controlling the creation process. Some of the patterns that fall under this category are: Constructor, Factory, Abstract, Prototype, Singleton and Builder.

Structural Design Patterns

Structural patterns are concerned with object composition and typically identify simple ways to realize relationships between different objects. They help ensure that when one part of a system changes, the entire structure of the system doesn't need to change. They also assist in recasting parts of the system which don't fit a particular purpose into those that do. Patterns that fall under this category include: Decorator, Facade, Flyweight, Adapter and Proxy.

Behavioral Design Patterns

Behavioral patterns focus on improving or streamlining the communication between disparate objects in a system. Some behavioral patterns include: Iterator, Mediator, Observer and Visitor.

This is just a recall article about design patterns. In upcoming article, we will discussing about JavaScript and jQuery design patterns. 

Till then, happy programming… :-)
 

Comments

Popular posts from this blog

Data Bound Controls in ASP.Net - Part 4 (FormView and DetailsView controls)

JavaScript - ES2015 (aka ES6)

The Clickjacking attack and X-Frame-Options