Wednesday, February 2, 2011

Studying jQuery

I'm reading Essential JavaScript & jQuery Design Patterns by Addy Osmani. He and many other gurus mentioned about "A Pattern Language". Should I read the book? It was published in 1977. Sounds old, but still referred. It means it's kind of Bible and people are interested "Pattern". I don't know how they are related. There is the main and most important book, "Design Patterns: Elements of Reusable Object-Oriented Software", which introduced and made "Design Patterns" popular to the world. It defines 23 core Object-Oriented design patterns.

Addy talked about Design Patterns in jQuery and Javascript. Here are Lists.

jQuery
  • Lazy Initialization
  • Composite
  • Wrapper
  • Facade
  • Observer
  • Iterator
  • Strategy
  • Proxy
  • Builder
  • Prototype
  • Flyweight

Javascript
  • Creational
  • Constructor
  • Singleton
  • Module
  • Revealing Module
  • Prototype
  • DRY
  • Facade
  • Factory
  • Decorator
What is a pattern?
A: A pattern is a reusable solution that can be applied to commonly occurring problems in software design. There are three main benefits from Design Patterns.

1. Patterns are proven solutions.
2. Patterns can be easily re-used.
3. Patterns can be expressive.

However, Patterns are NOT an exact solution. It provides an idea and prototype. It can be building blocks and you can customize it for your project.

"Reusing patterns assists in preventing minor issues that can cause major problems in the application development process". - So, you can focus on your problem more. These days nobody starts from the scratch unless it is required.

"Patterns can provide generalized solutions which are documented in a fashion that doesn't require them to be tied to a specific problem."

"Certain patterns can actually decrease the overall file-size footprint of your code by avoiding repetition." - DRY (Don't Repeat Yourself)

A Good Pattern does these.
- Solves a particular problem.
- The solution to this problem cannot be obvious.
- The concept described must have been proven.
- It must describe a relationship.

Here is the rule of three for a valid pattern.
1. Fitness of purpose. - How?
2. Usefulness. - Why?
3. Applicability. - Wide?

----

The structure of a design pattern.

A design pattern must have a
  • Pattern Name and a description
  • Context outline
  • Problem Statement
  • Solution
  • Design
  • Implementation
  • Illustrations.
  • Examples
  • Co-requisites
  • Relations
  • Known usage
  • Discussions
Writing Design Patterns
  • Bare in mind practicability
  • Ensure that you draw upon best practices.
  • Your design patterns should be transparent to the user.
  • Remember that originality is not key in pattern design.
  • Know the differences between patterns and design.
  • Your pattern needs to have a strong set of examples.








No comments: