Design pattern in Javascript

In software development , the design pattern is considered as reusable solution to any common problem statement. It is just like a sample code template that act as a solution. 

Design pattern can speed the development process by providing the well structured and  tested code samples.It also increases the readability for coders and architects. 

Taking about javascript the most widely used design patterns are :
1)Module Design Pattern : Javascript mainly emphasis on the module creating for keeping the particular piece of code independent with each other. We can consider it as loose coupling. Like classes we use ,  it incapsulates everything inside it. For example data members and the functions.Thus all the members are well separated from other class.Thus module design pattern provides the security in the form of access specifiers like private ,public ,protected

2)Prototype Design Pattern : Prototype design pattern is mainly used for creating object where performance matters. Suppose we have done an high level database operation .So, if again we need it at different place , then again we need to use the same operation. So solutions for that is to create a class define all the methods inside it and then create a clone/object for it . Now call all the functions through that object again wherever we require it

3)Observer Design Pattern : In programming architecture , we comes through some of the situations where we need to reflect the change on one part to gets reflected to other parts of the application.For example we use the $scope service in angular1.The observer pattern works in the same manner . when any one object gets changed , it always notify all it’s dependent objects

4)Singleton Design Pattern : The singleton design pattern mainly speaks about the reusability. It restricts the creation of more then one object, after the first object gets created.Like as service in angularjs 1.x follows the singleton design pattern. Once the object gets created , it’s reference gets used at all other places.For example suppose there are 10 peoples in a house.And also there is only one kitchen. then everyone uses the same kitchen for their food requirements.Because there is only one instance of kitchen there . No any other kitchen object created yet

By Pankaj Kumar Agarwal

Leave a reply:

Site Footer