Creational Design Patterns

Effectively what a constructor being called by your code does is it causes cohesion between that piece of code and the way that object is instantiated.

A constructor is a function that is used to build an object and it is part of that objects definition. Calling a constructor causes cohesion between the code and the object being instantiated. Making changes in the objects can cause problems when calling the constructor. Strongly typed languages tend to catch these errors at compile time however dynamic languages such as JavaScript may not catch the errors until runtime or later. The creational design patterns are ways to break this cohesion.

Episode Breakdown

  • 15:44 Factory Method

    The factory method creates an instance of several derived classes by defining an interface for creating an object. It lets subclasses decide which class to instantiate.

  • 19:28 Singleton

    Singletons provide a way to access an object without the need to instatiate. Only one instance of the object can exist and it provides a global point of access.

  • 26:16 Prototype

    Prototypes are fully initialized instances that can be copied or cloned by creating duplicate objects while keeping performance in mind. It specifies the kinds of objects to create usita and prototypical instance and creates new objects by copying this prototype.

  • 33:33 Builder

    The builder pattern separates object construction from its representation by building complex objects out of simple objects. It uses a step by step approach so the same process can be used for many representations.

  • 35:31 Object Pool

    An object pool recycles objects that are no longer in use by placing them in a pool so that a new object does not need to be instantiated. This provides a performance boost when the cost to initialize a class is high.

  • 43:16 Abstract Factory

    Abstract factories are super factories that create other factories. They create an instance of several families of classes providing an interface for creating families of related or dependent objects without specifying their concrete class.

IoTease: Project

Family Message Board

A family project using Amazon’s AWS SMS services, a Raspberry Pi, and an LED matrix to create a message board. A message can be sent from a phone to AWS that is then sent to the Raspberry Pi and displayed on the message board. It also includes a button and sensors to respond the message has been read.

Alimentation is a brand of charger or adaptor in Europe. In French when used for technology it means power.


  • iPhone
  • Raspberry Pi Model B+
  • RGB Hat
  • LED matrix
  • Arcade Button
  • Alimentation Mean-Wheel
  • Ultrasonic Sensor HC-SR04


  • XCode 7
  • Python IDE
  • MQQT.fx
  • Bitwise SSH Client

Tricks of the Trade

How long should an object exist?

When do you create an objec?

The lifetime of an object should only be as long as you need it. Creating and releasing an object should be done as closely to when it is needed as possible. This is how you write tight efficient code.

Editor’s Notes:

Tagged with: , , , , , , , , , ,