Skip to main content

Posts

The Decorator Pattern

--- --- Lesson 3 - The Decorator Pattern The Decorator Pattern (also known as the wrapper) is a Structural Design Pattern. Structural patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient. It allows us to dynamically add properties to objects at runtime. The goal is to combine a single concrete class with one or more Decorators. Definition Decorator is a structural design pattern that lets you attach new behaviours to objects by placing these objects inside special wrapper objects that contain the behaviours. The Decorator Pattern allows behaviour to be added to an individual object , either statically or dynamically without affecting the behaviour of other objects in the same class. - Wikipedia The Decorator Pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. - Head First Design Patterns Provides
Recent posts

The Strategy Pattern

Lesson 2 - The Strategy Pattern The Strategy Pattern is a Behavioural Design Pattern. Behavioural Design Patterns are design patterns that identify common communication patterns among objects and realise these patterns and in doing so increases flexibility, carrying out this communication. Definition The Strategy Pattern defines a family of algorithms, encapsulates each one and makes them interchangeable. Strategy lets the algorithm vary independently from the clients that use it. When to use ? When you want to use different variants of an algorithm within an object and be able to switch from one algorithm to another during runtime. When you have a lot of similar classes that only differ in the way they execute some behaviour. To isolate the business logic of a class from the implementation details of algorithms that may not be as important in the context of that logic. When your class has a massive conditional operator that switches between different variants of the same algo

Design Patterns

Design Patterns The purpose of this blog is to work through a few design patterns and note the important aspects of each. I will also be updating each article with relevant links to videos and articles that have helped me in my learnings.  Some of the patterns we will look at include:   The Factory Method  The Abstract Factory  The Strategy Pattern  The Decorator Pattern  Apart from the important aspects of each of the Design Patterns as well as the useful links to resources I will also include code examples from my bitbucket that will assist in providing a hands-on experience. The code demonstrating these patterns is written in Typescript.

The Factory Pattern

Lesson 1 - The Factory Pattern In this series we will be going through the various design patterns that are available. I will be using many different sources to gather information and all these sources will be listed in the links below. I will also be heavily referencing from the Head First Design Patterns Book which is definitely worth a read. At the bottom of each article there will also be links to some code examples for you to go through and play around with. So lets begin.  The Factory Pattern is a Creational Design Pattern. Creational Design Patterns are design patterns that deal with object creation mechanisms. In this tutorial we will look at the following : Simple Factory Factory Method. Abstract Factory. Definition Factory Method “The Factory Method Pattern defines an interface for creating an object but lets the subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to sub classes.” - Head First Design Patterns (Page 134) A