Solving problems using

design patterns

What is design?

Design is the creation of a plan or convention for the construction of an object, system or measurable human interaction

What are patterns?

A pattern is a discernible regularity in the world or in a manmade design. As such, the elements of a pattern repeat in a predictable manner.

What is a design pattern in software engineering?

A general reusable solution to a commonly occurring problem within a given context in software design.

 

It is not a finished design that can be transformed directly into source or machine code.

 

It is a description or template for how to solve a problem that can be used in many different situations.

Context

Day 0

The Request

User data is hard to ask for. Write a function that gets user data from lots of services and aggregates it

The Problem

User data is sparse (some fields might not exist), and irregular. It is difficult to work with objects that might contain incomplete or missing data.

Default Parameters &

Parameter Destructuring

codepen demo

Day 1

The Request

FakeBlock is extremely privacy focused, create a user object which contains a full birthdate, but only exposes the day and month.

The Problem

Javascript doesn't have a concept of public and private data members, in fact it doesn't really even have a concept of classes

The Revealing Module Pattern

codepen demo

Day 2

The Request

Add a comment feature to images

The Problem

Repetitive work is hard to maintain, leads to copy-paste-errors, JavaScript inheritance patterns can be deceptive

 

Combining (composing) functionality can be difficult and hard to keep compatible.

Add a comment feature to ads

 

Add a like feature to posts

Combine comments and likes to create enhanced posts

The -inator pattern

 

AKA decorator or mixin pattern

 

codepen demo

More Slides

 

HTTP://SLIDES.COM/CORYBROWN/CLASSICAL-INHERITANCE

Day 3

The request

We need a way to notify several services when someone comments: send to database, clear the cache, search for NSA keywords

The Problem

Your comment feature only has one callback to be executed on completion, and you don't want to refactor it every time a new notification request comes in

Pub Sub

Publish Subscribe

 

Codepen demo

Many Design Patterns

Not complete solutions, just repeatable solutions

 

https://addyosmani.com/resources/essentialjsdesignpatterns/book/

Javascript Design Patterns

By Michael Jasper

Javascript Design Patterns

  • 667