Design patterns in Javascript

Post on 25-Jan-2015

914 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

Transcript

Someone has already solvedyour problems.

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

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 little error in one module.

Allows to execute more than one method at the same 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 another the clients expect.

Lets classes work together that couldn't otherwise because of incompatible interfaces.

Decorator

Attach additional responsibilities to an object dynamically.

Decorators provide a flexible alternative to subclassing for extending functionality

Factory

Defines an interface for creating an object, but lets subclasses decide which class to instanciate.

Factory Method lets a class defer instanciation to subclasses.

Observer

Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

Command

Encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue or log requests, and support

undoable operations.

Facade

Provides a unified interface to a set of interfaces in a subsystem.

Defines a higher-level interface that makes the subsystem easier to use

Mediator

Defines an object that encapsulates how a set of objects interact.

State

Allows an object to alter its behavior when its internal 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 represent part-whole hierarchies.

Lets clients treat individual objects and compositions of objects uniformly.

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

top related