Someone has already solved     your problems.
•   Abstract those that vary.•   Program to an interface not an    implementation.•   Favor composition over inheritance.•...
Restricts the instanciation of a class to one object.
Avoids polluting globals.
Allow to use ‘function’ to obtain new objects.
Used to clone objects.In Javascript is used to create inheritance.
Decouple parts of the code in modules.Avoid failing your full application for some littleerror in one module.
Allows to execute more than one method at thesame line.Only one instance of object is needed.
Overwritte the behaviour of one method/functionto reduce time on further executions.Ideal for updates.
Memoize the executions that have been done.Reduce time on expensive jobs.
Nullify
Removes all references to local variables to avoid                 memory leaks.
Removes all references to local variables to avoid   memory leaks when the method/function               returns something.
Adapter
Converts the interface of a class into anotherthe clients expect.Lets classes work together that couldnt otherwisebecause ...
Decorator
Attach additional responsibilities to an objectdynamically.Decorators provide a flexible alternative tosubclassing for ext...
Factory
Defines an interface for creating an object, butlets subclasses decide which class to instanciate.Factory Method lets a cl...
Observer
Defines a one-to-many dependency betweenobjects so that when one object changes state,all its dependents are notified and ...
Command
Encapsulates a request as an object, thereby letting  you parameterize other objects with different   requests, queue or l...
Facade
Provides a unified interface to a set of interfacesin a subsystem.Defines a higher-level interface that makes thesubsystem...
Mediator
Defines an object that encapsulates how a set of                objects interact.
State
Allows an object to alter its behavior when itsinternal state changes.The object will appear to change its class.
Strategy
Defines a family of algorithms, encapsulates eachone, and makes them interchangeable.
Compose objects into tree structures to representpart-whole hierarchies.Lets clients treat individual objects andcompositi...
Separates elements of the application in layers.Logic, data and views are separated.
M.V.C
M.V.C
M.V.V.M
http://bit.ly/softhire
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Design patterns in Javascript
Upcoming SlideShare
Loading in …5
×

Design patterns in Javascript

1,276 views

Published on

Slides of the 'Design patterns in Javascript' talk in @MadridJS

Code from talk can be found in:

https://github.com/tcorral/DesignPatterns_code

Running examples in:

http://tcorral.github.com/Design-Patterns-in-Javascript/

Code of examples in:

https://github.com/tcorral/Design-Patterns-in-Javascript

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,276
On SlideShare
0
From Embeds
0
Number of Embeds
18
Actions
Shares
0
Downloads
25
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Design patterns in Javascript

  1. 1. Someone has already solved your problems.
  2. 2. • Abstract those that vary.• Program to an interface not an implementation.• Favor composition over inheritance.• Strive for loosely coupled designs between objects that interact.• Classes should be open for extension but closed for modification.• Depend on abstraction. Do not depend on concrete classes.
  3. 3. Restricts the instanciation of a class to one object.
  4. 4. Avoids polluting globals.
  5. 5. Allow to use ‘function’ to obtain new objects.
  6. 6. Used to clone objects.In Javascript is used to create inheritance.
  7. 7. Decouple parts of the code in modules.Avoid failing your full application for some littleerror in one module.
  8. 8. Allows to execute more than one method at thesame line.Only one instance of object is needed.
  9. 9. Overwritte the behaviour of one method/functionto reduce time on further executions.Ideal for updates.
  10. 10. Memoize the executions that have been done.Reduce time on expensive jobs.
  11. 11. Nullify
  12. 12. Removes all references to local variables to avoid memory leaks.
  13. 13. Removes all references to local variables to avoid memory leaks when the method/function returns something.
  14. 14. Adapter
  15. 15. Converts the interface of a class into anotherthe clients expect.Lets classes work together that couldnt otherwisebecause of incompatible interfaces.
  16. 16. Decorator
  17. 17. Attach additional responsibilities to an objectdynamically.Decorators provide a flexible alternative tosubclassing for extending functionality
  18. 18. Factory
  19. 19. Defines an interface for creating an object, butlets subclasses decide which class to instanciate.Factory Method lets a class defer instanciationto subclasses.
  20. 20. Observer
  21. 21. Defines a one-to-many dependency betweenobjects so that when one object changes state,all its dependents are notified and updatedautomatically.
  22. 22. Command
  23. 23. Encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue or log requests, and support undoable operations.
  24. 24. Facade
  25. 25. Provides a unified interface to a set of interfacesin a subsystem.Defines a higher-level interface that makes thesubsystem easier to use
  26. 26. Mediator
  27. 27. Defines an object that encapsulates how a set of objects interact.
  28. 28. State
  29. 29. Allows an object to alter its behavior when itsinternal state changes.The object will appear to change its class.
  30. 30. Strategy
  31. 31. Defines a family of algorithms, encapsulates eachone, and makes them interchangeable.
  32. 32. Compose objects into tree structures to representpart-whole hierarchies.Lets clients treat individual objects andcompositions of objects uniformly.
  33. 33. Separates elements of the application in layers.Logic, data and views are separated.
  34. 34. M.V.C
  35. 35. M.V.C
  36. 36. M.V.V.M
  37. 37. http://bit.ly/softhire

×