Web developers frequently interact with design patterns, even unknowingly, when creating applications.
So what is Design Patterns?
Design patterns are advanced object-oriented solutions to commonly occurring software problems. Patterns are about reusable designs and interactions of objects.
List of Design Patterns
- Constructor Pattern
- Module Pattern
- Revealing Module Pattern
- Singleton Pattern
- Observer Pattern
- Mediator Pattern
- Prototype Pattern
- Command Pattern
- Facade Pattern
- Factory Pattern
- Mixin Pattern
- Decorator Pattern
- Flyweight Pattern
Four Design Patterns Developers need to know
- Module
- Prototype
- Observer
- Singleton
Module Pattern
Modules should be Immediately-Invoked-Function-Expressions (IIFE) to allow for private scopes – that is, a closure that protect variables and methods.
Example :
(function() {
// declare private variables and/or functions
return {
// declare public variables and/or functions
}
})();
Prototype Pattern
The Prototype Pattern creates new objects, but rather than creating non-initialized objects it returns objects that are initialized with values it copied from a prototype - or sample - object. The Prototype pattern is also referred to as the Properties pattern.
var class1= function() {
this.var1 = 4;
this.var2 = 4;
}
class1.prototype.method1 = function() {
}
class1.prototype.method2 = function() {
}
Observer Pattern
There are many times when one part of the application changes, other parts needs to be updated. In AngularJS, if the $scope object updates, an event can be triggered to notify another component. The observer pattern incorporates just that – if an object is modified it broadcasts to dependent objects that a change has occurred.
Singleton Pattern
A Singleton only allows for a single instantiation, but many instances of the same object. The Singleton restricts clients from creating multiple objects, after the first object created, it will return instances of itself.
Video for Design Patterns
https://www.youtube.com/watch?v=mG20htjwoBY&list=PLqEsQbKGIlmrpvQcnidKsVWSCV6vjAHN9