06.07.2017 Views

Mastering JavaScript

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>JavaScript</strong> Patterns<br />

So far, we have looked at several fundamental building blocks necessary to write<br />

code in <strong>JavaScript</strong>. Once you start building larger systems using these fundamental<br />

constructs, you soon realize that there can be a standard way of doing a few things.<br />

While developing a large system, you will encounter repetitive problems; a pattern<br />

intends to provide a standardized solution to such known and identified problems.<br />

A pattern can be seen as a best practice, useful abstraction, or template to solve<br />

common problems. Writing maintainable code is difficult. The key to write modular,<br />

correct, and maintainable code is the ability to understand the repeating themes and<br />

use common templates to write optimized solutions to these. The most important<br />

text on design patterns was a book published in 1995 called Design Patterns: Elements<br />

Of Reusable Object-Oriented Software written by Erich Gamma, Richard Helm, Ralph<br />

Johnson, and John Vlissides—a group that became known as the Gang of Four (GOF<br />

for short). This seminal work gave a formal definition to various patterns and<br />

explained implementation details of most of the popular patterns that we use today.<br />

It is important to understand why patterns are important:<br />

• Patterns offer proven solutions to common problems: Patterns provide<br />

templates that are optimized to solve a particular problem. These patterns are<br />

backed by solid engineering experience and tested for validity.<br />

• Patterns are designed to be reused: They are generic enough to fit variations<br />

of a problem.<br />

• Patterns define vocabulary: Patterns are well-defined structures and hence<br />

provide a generic vocabulary to the solution. This can be very expressive<br />

when communicating across a larger group.<br />

[ 121 ]<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!