tag : design patterns

Patterns for Asynchronous Programming With Promises

Promises are currently the best tool we have for asynchronous programming and they appear to be our best hope for the forseeable future, even if they’ll be hiding behind generators or async functions. For now, we’ll need to use promises directly, so we should learn some good techniques for using them right now, especially when dealing with asynchronous operations on collections, whether they happen in parallel or sequentially.

Why Adapters and Facades Are Awesome

It’s been a long time since I’ve actually been on here teaching you something; 9 months since my last actual tutorial and really useful article. Sorry about that! I’m trying to get back on track now though. You should see much more frequent posting and hopefully some very useful posts. Anyway, this tutorial is about a great idea I implemented at work that involved the Adapter and Facade patterns. After using these patterns in this way, I have a much deeper respect for them and I want you to share that repect, so let’s take a look at some awesome ways/reasons to use them!

Dependency Injection With Node.js

Recently, I went over Dependency Injection to help you understand a simple way to decouple your code a little bit and help your testing out. Sometimes, though, in Node.js a module will depend on a system API provided by Node, which can make it pretty difficult to make sure that private dependency is being used properly. Normal dependency injection doesn’t work in this situation, but don’t give up hope just yet.

Event-Based Architecture: Getting Decoupled

Every JavaScript developer knows that events are quite normal in JavaScript and that an event-based system can be quite fun and simple to use. Most even use event mechanisms almost every time they write JavaScript, but have you tried taking it to the extreme? What does it look like when you have an application architecture that rarely has two objects communicating directly with one another?

Dependency Injection With JavaScript

When looking through design patterns that help to decouple objects in your applications, one of the simplest techniques to use is dependency injection. This is a common practice in Backbone.js, most notably when assigning models to views, but I haven’t seen it as much as I think I should. Here I’ll be examining what dependency injection is, how it helps, and how I’m putting it to good use in my latest project.

Book Review: Pro JavaScript Design Patterns

There are a lot of good books out there, whether they’re novels, references, or they teach you a skill or craft. In the JavaScript world, the book selection can be somewhat limited because it was only until semi-recent years that it took hold as a real language with real applicability, so older books on the subject can be a bit out of the loop. One of the books that treats JavaScript like a real language is Pro JavaScript Design Patterns.

JavaScript Closures and the Module Pattern

One of the most widely used design patterns in JavaScript is the module pattern. The module pattern makes use of one of the nicer features of JavaScript – closures – in order to give you some control of the privacy of your methods so that third party applications cannot access private data or overwrite it. In this post I’ll teach you what a closure is, how it works, and how to utilize it to implement the module pattern in your own JavaScript code.

JavaScript Design Patterns: Chain of Responsibility

We’ve made it to the final installment in the JavaScript Design Patterns series. That’s right, after this you’ll no longer have any clue what post will be coming out every Monday! Well today, we’ll be talking about the Chain of Responsibility Pattern. This pattern decouples the sender and receiver of a request. This is done with a chain of objects, each of which can handle the request itself or pass it on to the next object. Confused? Read on.

JavaScript Design Patterns: Command

The Command Pattern is a strange beast in the context of object-oriented programming. Unlike most objects, a command object represents a verb, rather than a noun. This is a little less odd in a language like JavaScript where functions are actually a type of object, but the classical sense of the Command pattern is still different than a function.

JavaScript Design Patterns: Observer

It’s time to introduce you guys to the Observer pattern. If you’ve been following this blog lately, you may have already had an introduction through my post talking about my jQuery plugin called JZ Publish/Subscribe. Well, here we’ll be talking about a few other ways to implement the Observer pattern, so you’ll know the method that works best for you and your application.